HomePHP Building Dynamic Queries with Chainable Methods
Building Dynamic Queries with Chainable Methods
Welcome to the fifth part of a 12-part series focused on method chaining in PHP 5. Through a set of comprehensive and easy-to-follow tutorials, this series of articles shows you how to create and use chainable methods within your own classes. It also teaches you how to implement this useful programming methodology for developing real-world web applications.
And now that you have been gently introduced to the main goal of this multi-part series, itís time to quickly summarize the topics that were discussed in the last installment.
In that article I explained how to create a simple, yet useful MySQL abstraction class. It was composed of a few straightforward methods for performing SELECT statements, accompanied by common query modifiers, such as the WHERE clause.
Of course, the most relevant detail to stress here with reference to the way that this class was built is that many of its methods were chainable. This made it possible to create and execute dynamic retrieval queries simply by linking one method to another. Period.
However, itís also possible to add more chainable methods to this sample MySQL abstraction class to extend its existing functionality. That's exactly what Iím going to do in the next few lines: implement an additional chainable method that will permit you to easily couple other typical query modifiers, like the ORDER BY clause to a SELECT statement.
Now, itís time to leave the preliminaries behind and continue turning the ďMySQLĒ class mentioned previously into a more functional element. Letís do it right now!