views:

3357

answers:

3

After graduating from calling the mysql_* functions directly in my code, I've stepped up to a home-brewed database abstraction class. Now, I'm beginning to think that I should really use a "professional" DB class instead.

I know there are a lot of them out there (ADODB, PDO, MDB2, etc) but I want to know which one I should try out. What do you feel is the best one and why?

+13  A: 

I really like PDO for my database access layer for the following reasons:

  • Object-Oriented
  • Supports Named Parameters
  • Part of the PHP Core as of 5.1.0 (thx to R. Bemrose for pointing this out)
  • Can be fairly easily extended to support custom features

That said, I am looking at going from my own custom wrapper for PDO that provides dynamic querying, simplified functions and the like to a full-fledged framework. I really like the Zend Framework and one benefit that I know it offers is that you can use either MySQLi or PDO with support for named parameters (something you don't get with the core mysqli library).

I will mention that though I originally started with using MySQLi, I had to switch to PDO because MySQLi had issues with large blobs. I don't know if that's still the case or not though.

Noah Goodrich
Actually, PDO is part of the PHP Core as of 5.1.0. In 5.0.x, it was out on PECL.
R. Bemrose
wow - 6 upvotes and no other answers so far... looks like PDO is the way to go..?
nickf
If you want just the core library go with PDO, but as I mentioned in my post and as Eran has just stated there is great benefit from picking a more robust database abstraction library like Zend_DB
Noah Goodrich
+9  A: 

I use Zend_Db extensively, and I like it for several reasons -

  1. The Zend_Db package is self contained and can be used without the entire Zend Framework library
  2. It works with plenty of database brands, so my code simply works even when PDO is not present
  3. It creates prepared statements even without access to a PDO wrapper
  4. It provides the foundation for more Zend_Db modules that are outsides the scope of PDO and which I use extensively (Zend_Db_Select, Zend_Db_Table, Zend_Db_Profiler and more)
  5. The source is available in PHP, which makes it very easy to browse through it to see how things are done
Eran Galperin
A: 

I recommend you take a look at Jeremy Zawodny's Database Abstraction Layers Must Die!

So -- do not use a database abstraction layer at all!

And he says, "I put my core data access layer into a library." To echo the second commenter on his blog, isn't that library in itself an abstraction layer, albeit a simple one?
TRiG