PEAR:DB Database Abstraction Layer

11.08.2005 at 09:31

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 underlaying 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 system 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 hole point about using a DB abstraction layer is to avoid this kind of thing, furthermore you will screw up if the connection property will once be private.

So you see, it's always up to you whether the code is really DB independent or not.

Enjoy.

Comments (0)

There are currently no comments available