Home arrow PHP arrow Building a MySQL Abstraction Class with Method Chaining

Building a MySQL Abstraction Class with Method Chaining

In this fourth part of a 12-part series on method chaining, I start building a basic MySQL abstraction class that implements a few straightforward methods. Of course, the methods can be easily chained to each other, which permits us to build different parts of a SELECT statement through a truly compact and readable API.

TABLE OF CONTENTS:
  1. Building a MySQL Abstraction Class with Method Chaining
  2. Building a MySQL abstraction class
  3. Defining a chainable method to perform SELECT statements
  4. Building the WHERE part of a query
By: Alejandro Gervasio
Rating: starstarstarstarstar / 1
November 02, 2009

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Put it in a simple way, method chaining is a handy programming methodology that allows you to create classes whose methods can be easily linked to each other, thus building a highly compact API.

Building chainable methods is not a proprietary approach supported by a particular programming language. It can be applied to multiple languages. In the case of PHP 5, it is very simple to implement, even if you have an average background in the object-oriented paradigm.

Therefore, if you’re a truly passionate PHP developer who wants to learn the basics of building chainable methods and how to use them in real-world applications, then don’t hesitate any longer; start reading this series of articles now!

Right now I'm going to review the topics that were discussed in the previous part. In that tutorial I finished building a simple string processor class, which could apply different filters to an incoming string.

Of course, apart from the simplistic logic implemented by the methods of this sample class, the most important aspect to stress here is that these methods were completely chainable, thus making it possible to invoke them by writing only a few lines of short, tight code.

However, this class was built only as an introductory example, handy for learning the fundamentals of applying method chaining in PHP 5. But this approach can be used for developing more useful applications. So, with that idea in mind, in the next few lines I’m going to explain how to create a simple MySQL abstraction class whose methods will be chainable.

Now it’s time to see how to use method chaining to abstract access to MySQL. Let’s get going!



 
 
>>> 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 2 - Follow our Sitemap

Dev Shed Tutorial Topics: