PHP – Implementing a Data Access Layer

databaselayersPHP

I am currently reviewing a code base and noticed that a majority of the calls (along with DB connections) are just buried inside the PHP scripts. I would have assumed that like other languages they would have developed some sort of data access layer (Like I would do in .Net or Java) for all of the communication to the DB (or implemented MVC, etc). Is this still a common pattern in PHP or is there alternative methodologies/patterns for this technology? I am just trying to understand why the subs would have developed it this way.

Any insight/info on how experienced developers design an approach data access in PHP would be very much appreciated.

Best Answer

It is pretty common in PHP Projects to have some kind of Data Abstraction or Data Access Layer. Simply because of DRY Principles and cleaner error handling. Experienced Programmers don't like to repeat themselves over and over again and they seperate domain logic from data manipulation as much as possible.

There are lots of very good Frameworks and components out there to help with Data Abstraction or even Object Relational Mapping, see this Post at SO.

You might experience what lots of other code reviewers experienced before:

WTFs per Minute

(from: http://www.osnews.com/story/19266/WTFs_m)

Related Topic