HomePHP The mysqli Extension and the Active Record Pattern
The mysqli Extension and the Active Record Pattern
The active record pattern allows you to access records in a database by means of a unified interface, generally composed of a few data mapper objects. However, as with other popular design patterns, there are several methodologies for implementing it within an object-oriented application, all of which can be used to obtain similar results. In this group of articles, I demonstrate how to progressively build a MySQL abstraction class that uses the active record approach for performing CRUD operations (Create, Retrieve, Update, Delete) on the records of a selected database table.
Naturally, if you've read the six preceding articles (this is the seventh and concluding part) then by now you're pretty familiar with creating a class like this. In those articles I explained how to develop a sample MySQL-accessing class that was capable of inserting, updating and deleting records, as well as performing conditional SELECT statements against a specified MySQL table.
In this case, the class accomplished all of these database tasks by way of a slightly modified version of the active record pattern, since no mapper objects were used here. Instead, it implemented a few straightforward methods for executing dynamic queries through a highly-simplified API.
We're not quite finished with this quick overview on accessing MySQL tables with the active record pattern yet, because there’s one step that remains undone. What is it? Well, as you’ll surely recall, I built this class by using the old MySQL library included with the PHP distribution, which is good and efficient.
But it’s worth making the effort to see how this sample class can be rewritten by using the newer, revamped “mysqli” extension. Thus, this last episode will be dedicated exclusively to doing this, so you can have at your disposal an enhanced versions of the class.
Are you ready to tackle this final chapter of the series? Then go ahead and start reading now!