You can use either PHPLIB or PEAR's Database Abstration Layer.
I don't know how mature PEAR'S DB Layers is but I have used PHPLIB's for Sybase and MySQL and everything has worked great so far.
These Database Abstractions Layers do NOT however automatically change you SQL Statement to fit a certain database.
These DB Layers only wraps the database functions. For example you call $db->query("select foo from bar") instead of database specific functions.