Chapter 34. Using PEAR DB with PHP
PEAR DB is one of several wrappers around PHP's database extensions that seek to generalize the concept of a database connection. PEAR DB is fully object oriented. With PEAR DB implemented in your software, you'll find it easier to allow your application's users to select from several databases (the list of supported databases includes all the majors, and plenty of second-string players as well). You may also find it easier than before to handle errors and react to unexpected occurrences that take place during connections and queries.
This chapter aims to explain what PEAR DB is all about. It's not hard, but it is important that you understand PEAR DB in theory and practice, because there are substantial pros and cons to its use. We start with a general discussion of the benefits and costs of a database abstraction layer; then we explain the basics of using the PEAR DB package.
For reference, examples, and further explanations of concepts, have a look at the PEAR DB web site at http://pear.php.net/package/DB
.
Note
For general information on PEAR and instructions on how to locate and install PEAR libraries, see Appendix E.
Pear DB Concepts
There are a number of concepts in PEAR DB that you must understand to work with the class effectively. These include:
Data Source Names (DSNs)
Connection
Query
Row retrieval
Disconnection
The following subsections explain each of these items in turn.
Data Source Names (DSNs) ...
Get PHP6 and MySQL® 6 Bible now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.