HomePHP Completing the MySQL Class with Method Chaining
Completing the MySQL Class with Method Chaining
Among the numerous features provided by PHP 5, there’s one that many developers find appealing. It permits the building of compact and modular programming interfaces. Yes, as you may have guessed, in this specific case I’m talking about method chaining, a programming approach can be easily mastered by those with an average background in the object-oriented paradigm. This is the sixth part of a 12-part series on method chaining.
Indeed, learning how to create chainable methods in PHP 5 class is a pretty straightforward process that will make your own classes more compact and modular as well. Therefore, I suggest you read this series of articles; in it, you'll find an approachable guide that will show you the basics of using method chaining and how to implement this approach for developing real-world programs.
And now that you're aware of the main goal of this series, it's time to review the topics that were discussed in the last article, as a quick reminder. In that installment I showed how to add a simple chainable method to the MySQL abstraction class previously developed. It was used for creating the "ORDER BY" part of a SELECT statement.
Defining a method like this allowed us to retrieve database records by using only a few lines of compact code. Now I'd like to finish building this sample MySQL abstraction class by adding to it two final chainable methods. The first one will be charged with building the "LIKE" clause of SELECT queries, while the second method will be a factory responsible for returning to client code only singletons of this class.
Want to see how these two useful methods will be defined? Then click on the link that appears below and keep reading.