PHP Data Objects, Light Weight Data Abstraction (PDO)
We have been using PDO now for a while, its a good lightweight Data Abstraction tool and while using objects is not too heavy such as a full Object Relational Modelling Solution. We have used Symfony as a framework, which uses the Propel ORM for its Data Abstraction Layer, which is quite good but can be inappropriate for some jobs. PDO runs queries in the c layer and as such is quicker at querying databases, it also supports many drivers for Relational Databases such as MySQL, Oracle, PgreSQL, SQL Server and many more...
Real benefits of using PDO over straight mysql queries are:
- Faster to execute queries
- Works easily with objects
- Swap the PDO Data Driver between databases easily
- Construct queries and store them to be called later
- Transaction based querying
- Rollback changes made using the Active PDObject
We have a PDO set up available for download at the bottom of this page, it uses an ini file in the conf directory to set up the driver, host, user, password and database, it also has pretty good error handling and will check to see whether the PDO driver you are using is supported.
The downloadable files include a brief list of functions, which can be easily expanded upon, these functions are:
<?php db_query("show tables;"); ?>
<?php db_put(db_query("update pages set status = 1;"));?>
<?php db_get(db_query("select status from page")); ?>
<?php db_get_object(db_query("select status from page")); ?>
| Attachment | Size |
|---|---|
| Sample PDO DB Functionality (db-sample.tar) | 8.5 KB |

If you have a project, which has failed, stalled or been dropped.