HomePHP Updating and Deleting Database Records with the Active Record Pattern
Updating and Deleting Database Records with the Active Record Pattern
Regardless of its rather intimidating name, the active record pattern is actually quite simple to implement with PHP when developing database-driven applications. Indeed, this pattern permits you to achieve a high level of abstraction when performing typical operations, such as insertions, updates and deletions of records, since all of these tasks are handled transparently by data mappers objects or a data access class.
Therefore, if you're interested in learning how to implement this useful pattern within a MySQL abstraction class, then this series of articles might be what you really need. In it you'll find numerous examples that will help you to master this topic by mean of a hands-on approach, and best of all, with minor hassles.
Of course, if you already read the previous article, then you're familiar with utilizing the active record pattern in conjunction with a MySQL abstraction class. In that particular tutorial I discussed this topic extensively, and hopefully this experience has been instructive for you.
In simple terms, this MySQL-handling class was provided with the ability to fetch and insert database rows without the need to code explicitly any SQL statements. This can be fairly helpful in achieving a neat level of SQL abstraction.
However, this educational journey has just started. It's possible to apply this pattern to update and delete rows from a selected MySQL table. Therefore, in the next few lines I will demonstrate how to perform updates and deletions through the sample MySQL class developed in the previous tutorial.
Now, it's time to learn how to use the active record pattern for performing database updates and deletions in a few simple steps. Let's jump in!