Journal Journal: php data access abstraction layer
I've been thinking about this for awhile. After working on an Auction Management System for one of the many ebay consignment companies, working on my own home page and other smaller utility scripts, I came up with this idea of a data access abstraction layer.
This doesn't have to apply to just for php. When I am writing my web application, I think about (and maybe like to) the raw SQL to access and modify my data storage. It takes awhile to really grasp that, just like you don't want HTML in your code, do your really want your SQL in your application? Maybe. Probably not.
What Smarty does for PHP and HTML, I want something to do this for PHP and SQL/XML.
Not sure about most of you, but I love hashes (associative arrays). This, by far, is why I love php/perl and use it. [ Second reason is the foreach statements, if you care. ] I'll often use perl (or php) instead of shell, just for these reasons.
So, when I'm writing my web application (or sys admin script), I'll want a couple common things. Some sort of argument processing, a configuration file, and then access to the data. Quite honestly, when writing the script or application, I don't want to think about the XML structure of the config file, or the table structure and SQL syntax of the database. I just want to say "get" data, and set/update data, and I want this done in like two or three lines, and I want the results in hashes. Something along the lines of
$verbose = $arg["verbose"]
or
if ( $user[$userid]["password"] == $arg["password"] ) {
All the database abstraction layers I've seen and found want to wrap the drivers, but still seem to let the SQL get push up to the top. Why ? Well, I guess that is not the goal of database abstraction. I guess that is what I want too, but I want another layer, data access abstraction. I want an object that can get, set, update, insert, and search. If I want to prototype with XML files, locally, then move to a database later, I shouldn't have to change the application code, just the configuration for the data access layer.
I was kind of hoping someone (with better OO design skills) had made a simple, lightweight version of this. I am planning on writing this myself, but the exact design (and time) is escaping me. This idea, if not clear yet, is :
Application
---> data access abstraction
---> storage implementers (mysq, pgres, xml, ini)
---> storage
What is important, is that the application layer contain nothing specific to tie that code to the specific storage. The DAA layer should read the configuration file, select the storage implementation (plugin?, module ?), and setup the data to object mappings.
There will be limitations, of course, with this idea. Some of then advances uses of databases may get blocked. Not sure what they all are, as I probably don't use them. Because, DAA needs to be kind of blind to specific storage features, and the application cannot know about them either. So, if they can't be implemented in the plugin/module, and selected via a configuration file, then they can't be used. I'll accept this limitation.
My data storage requires are: MySQL, XML Files, and LDAP. I'd prefer configuration files in XML, but if you can convince me INI is better