Last modified on 15 December 2010, at 07:21

PHP Programming/dbal

What is a database abstraction layer?Edit

A database abstraction layer (dal) is a couple of functions or a class which deals with every aspects of database handling.

First of all you have a function to connect and to disconnect to/from the database. You also have some functions to submit a query, and to get the results and finally you need to have some error-handling functions too.

Why to use a dal instead of the regular php funcitons?Edit

Of course you do not replace the php-functions, you just connect them to get a better performance when you need to develop your code, validate the data, etc...

If you use a really flexible dal, then you do not need to change every line of your code if you switch from one database type to the other.

How to write a dal?Edit

Most users should not be writing their own DAL, since there are several ready-to-use open-source DALs available. One of the benefits of a DAL is to make code more reusable, and writing your own DAL (unless it achieves wide acceptance in the PHP community) is counterproductive. The most common one is the PEAR:DB package which is already installed on the majority of web servers.

You can find some less sophisticated dals in the source files of some well written open-source CMS sites also.