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
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- 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...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: