If your PHP app needs to talk to a database, there's a lot of debate as to whether you should use PHP's native database extensions (e.g. mysqli and pgsql) or PHP's new PHP Data Objects. mysqli and pgsql talk directly to their respective databases, whereas PDO is a database abstraction layer; it provides a common interface to talk to several different databases.
Many developers say that you should use PDO, but I disagree. The two primary reasons for using PDO are:
Those are both very valid points, and on the surface they sound great. But consider this:
mysqli_*
and pg_*
commands.I don't hate PDO, and have used it in the past for simple apps, but I generally think you're better off using a native extension.
As of this writing (May 2009), Zend has a new database interface module out, called Zend_DB. It's sort of like a database abstraction layer combined with a set of database helper functions. It has methods like insert()
and update()
which let you automatically insert/update data without having to write a lot of SQL, as well as all the standard methods (e.g. query()
) that any good abstraction layer provides. It actually uses the PHP database engines under the hood (mysqli, pgsql, PDO, etc.), and even gives you direct access to them via the getConnection()
method.
I've been using Zend_DB recently, mainly with the mysqli engine, and so far I like it. It provides ready-made versions of a lot of the helper functions that I usually write myself, like quote()
and quoteIdentifier()
. And since it provides direct access to the underlying connection, it doesn't limit me from using advanced functionality if I need it. Still, Zend_DB does introduce one more layer your data has to go through, so it may be overkill for some projects. But it's certainly worth a look.