PHP includes such "reasonable database layer"...
Posted Dec 19, 2011 8:17 UTC (Mon) by khim
In reply to: Cracks in the Foundation (PHP Advent)
Parent article: Cracks in the Foundation (PHP Advent)
A reasonable database layer allows one to switch database backends as needed.
It's called PDO and PHP had it for years.
It allows me to change the backend driver (a one-line edit), and everything should still work afterwards.
It allows you to change the backend driver
and this starts long arduous task of fixing the code. Even trivial tasks (like addition of one row) is done differently with different servers. For example in mysql you usually add row using insert and then call PDO::lastInsertId to find the ID, but in Postgresql it does not work and the best alternative is to use INSERT
RETURNING foo_id. Or you can use PDO::lastInsertId, but this is slower and requires changes anyway (you must specify name of a sequence object with Postgresql).
Sorry, but magic wand does not work with SQL servers: they all are so different that "multiple backends" paradigm works only if you test your program with all of them. Or you can use some kind of ORM library, but this creates it's own problems.
to post comments)