-
Book Overview & Buying
-
Table Of Contents
Learning PHP Data Objects
By :
PHP Data Objects, (PDO) is a PHP5 extension that defines a lightweight DBMS connection abstraction library (sometimes called data access abstraction library). The need for a tool like PDO was dictated by the great number of database systems supported by PHP. Each of these database systems required a separate extension that defined its own API for performing the same tasks, starting from establishing a connection to advanced features such as preparing statements and error handling.
The fact that these APIs were not unified made transition between underlying databases painful, often resulting in the rewriting of many lines of code, which in turn, led to new programming errors that required time to track, debug and correct. On the other hand, the absence of a unified library, like JDBC for Java, was putting PHP behind the big players in the programming languages world. Now that such library exists, PHP is regaining its position and is a platform of choice for millions of programmers.
It should be noted, however, that there exist several libraries written in PHP, that serve the same purpose as PDO. The most popular are the ADOdb library and the PEAR DB package. The key difference between them and PDO is speed. PDO is a PHP extension written in a compiled language (C/C++), while the PHP libraries are written in an interpreted language. Also, once PDO is enabled, it does not require you to include source files in your scripts and redistribute them with your application. This makes installing your applications easier, as the end user does not need to take care of third-party software.
Here, we are neither comparing these libraries with PDO nor advocating the use of PDO over such libraries. We are just showing the advantages and disadvantages of this extension. For example, the PEAR package, MDB2, has richer functionality of an advanced database abstraction library, which PDO does not.
PDO being a PECL extension, itself relies on database-specific drivers and on other PECL extensions. These drivers must also be installed in order to use PDO (you only need the drivers for the databases you are using). Since the description of installation of PDO and database-specific drivers is beyond the scope of this book, you can refer to PHP manual at www.php.net/pdo for technical information regarding installation and upgrade issues.
PECL is PHP Extension Community Library, a repository of PHP extensions written in C. These extensions offer functionality that would be impossible to implement in PHP, as well as some extensions that exist for performance reasons as the C code is much faster than PHP. The home page of PECL is at http://pecl.php.net
Change the font size
Change margin width
Change background colour