Home arrow PHP arrow 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.

TABLE OF CONTENTS:
  1. Building Dynamic Queries with Chainable Methods
  2. Review: dynamically building SQL queries with method chaining
  3. Working with ORDER BY clauses
  4. Fetching database rows with the chainable orderby() method
By: Alejandro Gervasio
Rating: starstarstarstarstar / 1
November 04, 2009

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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!



 
 
>>> More PHP Articles          >>> More By Alejandro Gervasio
 

blog comments powered by Disqus
   

PHP ARTICLES

- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 7 - Follow our Sitemap

Dev Shed Tutorial Topics: