I’ve been a little busy with moving, so that is my excuse for being AWOL. Let’s continue.
I learned that Ikea dressers require far more effort to build than beds. Probably twice as much time and effort.
I learned that the California Department of Corporations has wacky accounting that seems to work against their best interest. I just received a full refund for a processing fee they kept requesting last year. Strange.
I learned that it is unexpectedly rare to find web developers who have tried creating their own object-oriented database abstraction layer. I found it is even more rare to find developers who took this abstraction layer and made the (in my opinion) relatively obvious step toward creating a generalized abstraction layer that removes the need to write SQL 90% of the time. For those of you who haven’t thought about this before, creating such a layer, the pride and joy of the rails movement, is relatively simple. While there are many schools of thought on how to accomplish this, I think a simple place to start is to setup something like this:
// Notice my example assumes any table you want.
$object = new DBLayer(‘tablename’);
// Runs an equivalent of SELECT * FROM tablename WHERE
// primary_key_field = 30;
$object->load(30);
// Overload PHP5’s __set() method (see documentation)
// store this in an internal array so that table fields like
// ‘tablename’ don’t accidentally erase object settings.
// Thus, “$this->mData[‘username’] = $value;”
// Just see the documentation of __set(). Trust me.
$object->username = ‘new username’;
// runs an equivalent of UPDATE tablename SET username=’new
// username’ WHERE primary_key_field = 30;
$object->save();
There are many ways to figure out the primary key. One idea is to standardize the primary key name so that “tablename” always has a primary key of “tablename_id”. Another idea is to dynamically determine it by running a “DESC tablename” and caching the results. Think it over. It’s an interesting, but highly insightful challenge. My example may be a little advanced, but this is the starting point of those shiny “rails frameworks” you hear about.
One thought on “Catching up (8, 9, 10)”
Comments are closed.