I did this.
There actually are abstraction layers available already, such as "ADODB" which doesn't really have anything to do with MS ADODB, but it's mimicing it's functionality.
I used PostgreSQL for a long time and wrote an abstraction layer called "DBXS", which I also modeled somewhat after ADODB.
I just prefer it because I have an object fixation 🙂
$database = new DBXSConnection($connectionString);
$database->open();
$recset = $database->query($sql);
while (!$recset->eof())
{
$id = $recset->fields[0];
$name = $recset->fields[1];
$email = $recset->fields["email"];
$recset->movenext();
}
$database->close();
The idea was that if I ever needed to use a different database that I could do that. Now, a little while ago I started converting everything to MySQL (this is a pain, and still going on).
Because DBXS only worked with PostgreSQL before, I needed to add the functionality for MySQL now, which wasn't all that hard. Some of the mysql_ functions have different names, and passing the connection parameters is different also, but with some adjusting I managed to whip up a MySQL specific DBXS class that let's me use all my existing queries without modification (aside from formatting dates)
I have a class.dbxs.pgsql.php file and a class.dbxs.mysql.php file, then i just create a "class.dbxs.php" symlink for whichever of the two I need.
Granted, this is not because I need to do this, but because I want to, and because I have the programmer's syndrome (i.e. reinventing the wheel). But it has been a fun experience.