views:

126

answers:

2

In PHP, what is the best practice for laying out the responsibilities of a Db Abstraction Layer?

Is OOP a good idea in terms of performance? How much should be generic object code, and how much should be very specific functions?

+1  A: 

There are already some great solutions for this. A DAL is not a simple thing, especially since so many security concerns are involved. I would suggest checking out PDO and MySQLi. Even if you write a wrapper class for one of them, the heavy lifting will be done for you in a robust and secure way.

Lucas Oman
+1  A: 

In most applications I have written, there are generally two different types of data access. One is for transactional operations: retrieving specific objects from the datastore, modifying them and saving them back. I've found a solid ORM to be the best solution here. Don't try writing your own (as interesting as it might be.)

The other common type of data access is for reporting. ORMs aren't the best solution here, which is why I usually go with a scheme that uses custom SQL queries. Plain ol' PDO works well here. You can create a special value object just for that report and have the PDO query fetch the values into the object. Reports need to be fast and building them using an ORM layer is usually just too slow and cumbersome.

Unlabeled Meat