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.

  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



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


- 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: