PEAR:DB Database Abstraction Layer

Nowadays web applications need to be flexible and so it is wise to use a database abstraction layer, so it will be easy to exchange the underlying DBMS. There are quite a few projects out there who provide this functionality, PEAR:DB PEAR:MDB and AdoDB are probably the most popular ones.

While developing this page I took a closer look at PEAR:DB mostly because it is a part of PEAR and therefore available on most systems by default. Furthermore it’s API is straight forward and the documentation is usable. Additionally I can recommend reading the excellent Quick Start Guide to Pear DB.

Since PEAR:DB aims to support multiple DBMS they need to make some compromises, for example not all DBMS support something like mysql_insert_id() therefore such a feature has to be emulated. In case of PEAR:DB this is done with sequences.

Of course you could do an ugly hack like this:

mysql_insert_id($DB->connection);

However this is DBMS-specific code and the whole point of using a DB abstraction layer is to avoid this kind of thing. Furthermore, you will be screwed if the connection property will be hidden in the future.

Hence, it’s always up to you whether the code is really DB independent or not.