Home arrow PHP arrow Working with MySQL Result Sets and the Decorator Pattern in PHP

Working with MySQL Result Sets and the Decorator Pattern in PHP

If you’re one of those avid PHP developers who wants to learn how to apply the decorator design pattern within your Web applications, then this group of articles might be quite appealing to you. Welcome to the second part of the series “Using the Decorator pattern with PHP.” Comprised of two parts, this series walks you through the core concepts of using this pattern in PHP, and shows you its practical edge with numerous hands-on examples.

TABLE OF CONTENTS:
  1. Working with MySQL Result Sets and the Decorator Pattern in PHP
  2. Handling MySQL result sets
  3. Retrieving MySQL result sets without changing the original class
  4. Defining multiple decorator classes
By: Alejandro Gervasio
Rating: starstarstarstarstar / 12
September 05, 2006

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Introduction

For those readers that just found this article after doing some research on the Web, let me tell you that in the previous tutorial, I explained the foundations of the decorator pattern in PHP, and developed an easy-going example to show how it works. Basically, this pattern will allow you to add more functionality to an existing class, without having to change its original structure.

As I mentioned right at the beginning of this series, this result also might be achieved by using inheritance and creating some subclasses from a base class. However, depending on the context where an application will be developed, there are times when it’s preferable to work with objects of different types, instead of using child objects that belong to the same family.

Whatever reasons you have for using objects of different types, the fact is that creating decorator objects in PHP is admittedly easy. In this second article, I’ll take advantage of this handy feature by demonstrating how the decorator pattern can be used in a real situation that you probably tackle very often: processing MySQL result sets.

Definitely, the pattern in question can be used for generating different types of outputs (or views) based on a returned result set, by using a few decorator classes that I’ll define in the course of this tutorial. Hopefully, when you finish reading these lines, you should have a clear idea of how to include decorator classes in your object-based PHP applications.

Are you ready to learn more about the decorator pattern? Okay, let’s get started!



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

Dev Shed Tutorial Topics: