HomePHP The LIKE Clause and the Active Record Pattern
The LIKE Clause and the Active Record Pattern
In most cases, the implementation of the active record pattern in PHP (and other programming languages too) is carried out through a few data mapper objects, which are used to perform CRUD operations on a group of targeted database tables. This seven-part article series describes the advantages of using the active record pattern in a variety of situations, and shows you how to do it.
While an approach like the one described above permits to reach a high level of SQL abstraction when accessing databases, the truth is that it’s also possible to apply the active record approach by means of a single database class, which encapsulates within its API all the logic required for executing CRUD tasks.
Logically, when using this methodology, programmers won’t need to code any SQL statements directly, since the class will dynamically construct the SQL queries required for performing records insertions, updates, deletions and so forth.
In this group of articles, you’ll be provided with an approachable guide to building a database abstraction class like the one mentioned above, which will let you easily perform the most common database-related operations without having to write a single portion of SQL code.
At this point, you possibly recall that in the preceding tutorial I explained how to build a simple MySQL abstraction class, which could run conditional SELECT statements by utilizing a slightly different version of the active record pattern. Essentially, this class was capable not only of dynamically arming SELECT queries, but working with WHERE clauses, which made running conditional SQL commands a no-brainer process.
However, in its current incarnation, this class's functionality is limited, regardless of its decent level of SQL abstraction. Therefore, in this fourth part of the series I’m going to enhance it by making it capable of working with LIKE clauses in a straightforward way.
Now it’s time to get rid of the preliminaries and continue extending the functionality of the MySQL-accessing class developed in the previous article. Let’s get going!