Page 246 - Open Soource Technologies 304.indd
P. 246

Web Technologies-I



                   Notes         the “mysqldump” utility for this purpose. The command is issued from the command line, not
                                 within the “mysql” program.
                                 mysqldump -uuser -ppassword -hhost.domain.com database > filename.sql
                                    •  -u specifies the database user account to use
                                    •  -p specifies the database user password to use

                                    •  -h specifies the database server to connect to
                                    •  database specifies the database to act on
                                    •  > filename.sql directs the output to a file. Normally output is directed to the screen.

                                 The output of a mysqldump can be directed back into a blank database to recreate a complete
                                 set of tables and data. This is especially handy if you develop a structure on a staging system
                                 and need to quickly and easily move the whole contents of a database to a new system. Here
                                 is the command to do that using the “mysql” utility.
                                 mysql -uuser -ppassword -hhost.domain.com database < filename.sql
                                    •  -u specifies the database user account to use

                                    •  -p specifies the database user password to use
                                    •  -h specifies the database server to connect to
                                    •  database specifies the database to act on

                                    •  < filename.sql directs the mysql program to read instructions from a file instead of the
                                      command line.



                                              Develop a PHP program to connect your page from the database.



                                 10.3 PEAR DB Basics

                                 PEAR supplies a number of open source extensions to PHP including its DB package, which
                                 provides a database abstraction layer, so that the PHP programmer does not have to worry
                                 about all the APIs for different databases.

                                 10.3.1 Advantages and Disadvantages of PEAR DB
                                 Whether or not you decide to use PEAR DB or a similar database abstraction layer depends
                                 on your needs. If you need to be able to work on many applications and get your work done
                                 quickly, then PEAR DB is certainly helpful. If performance is key, then you may find the extra
                                 weight of PEAR DB to be prohibitive.
                                 10.3.2 Why use a database abstraction layer?

                                 One big benefit of using a database abstraction layer like PEAR DB is portability. PEAR DB
                                 allows you to use a single API for working with many different types of databases. So if you
                                 decide to move to another database, you will not have to rewrite all your code.

                                 Another benefit is code simplification. If your application involves multiple databases of different
                                 flavours or you work on many applications each of which uses a different type of database, you
                                 would normally have to learn the APIs for each of the databases you would be working with.
                                 Again, PEAR DB allows you to work with all these databases using the same API.




        240                               LOVELY PROFESSIONAL UNIVERSITY
   241   242   243   244   245   246   247   248   249   250   251