Adventures in the Land of PDO

I have just started investigating the possibilities of using PHP5’s ‘PHP Data Objects’, or PDO, as a way of accessing databases. This has come after years of using PEAR’s excellent PEAR::DB (now superceeded but still maintained), and more recently PEAR::MDB2 (the successor to PEAR’s DB package).

Well it is said that first impressions last, and I have to admit that I certainly was! After doing some reading around PDO, it became apparent that there are several reasons why PHPers (those using PHP5 anyway) should be conversing with their databases using PDO.

The PDO documentation at PHP.net explains that whilst PDO provides a new and lightweight interface for connecting with DBs, it should not be seen as a Database Abstraction layer - it does not rewrite queries or emulate features not available on all DBs.

What they say it is, is a Data Access Abstraction layer - meaning that you can issue the same commands for accessing data no matter which DB you happen to be talking to. So good bye to having to reconcile mssql_rows_affected for MSSQL and mysql_affected_rows for MySQL for example.

PDO is extensible at runtime - you can load different DB drivers on the fly using dl() instead of having to uncomment the relevant lines in your php.ini file. This is great, as it means that you do not have to worry about recompiling your PHP installation because you decided to use a different DB.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blogmarks
  • co.mments
  • del.icio.us
  • digg
  • Fark
  • Furl
  • Reddit
  • Spurl
  • TailRank
  • YahooMyWeb

About this entry