Question

I was playing around with creating a database abstraction class for learning purposes where you can create multiple connections to whatever databases you have drivers for by doing something like:

//Create multiple database connections
$db1 = new DatabaseFactory("MySQL","root","","localhost");
$db2 = new DatabaseFactory("MySQL","root","","localhost");

or...

$db = new DatabaseFactory("SQLite");

But I got to thinking about it, and unless you need to manage multiple connections with a factory object, there really isn't a need for something like this with the advent of PDO correct?

My question is, do you think it is useful to have further layers of abstraction to PDO and why?

Was it helpful?

Solution

If thinking strictly database level operations abstraction, and not things like ORM, there is still the issue of the SQL support between different databases.

For example, comparing SQLite, Postgre and MySQL, all of them support much of the same syntax, but there are also various differences between the bunch.

PDO does not take any measures to abstract away the differences in SQL support between the platforms.

There's also some other things that could be hidden using another layer. However, whether it's very doable or not is a bit doubtful. Consider for example trying to use software to emulate foreign key checks in SQLite or such.

OTHER TIPS

While PDO is a big improvement over the older mysql function bucket, it is still a very low level API for accessing the database.

So yes, for most situations it does still make sense to wrap a higher level API around it.

For example, a higher level API can be used to make SQL injection attacks virtually impossible.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top