Home arrow PHP arrow Page 5 - Object Interaction in PHP: Introduction to Aggregation, part 2

Implementing the “MySQLConnector” class: a practical example - PHP

In this second part of his series, Alejandro Gervasio gets a little more technical with the basics of Aggregation. He begins working with a MySQL abstraction class and a useful paging class, and is starting to get into writing portable code and introducing the technique of aggregation.

  1. Object Interaction in PHP: Introduction to Aggregation, part 2
  2. Fetching data with class: the “MySQLConnector” class
  3. Adding Some Functionality to the Class
  4. Improving the “MySQLConnector class: adding row-counting methods
  5. Implementing the “MySQLConnector” class: a practical example
By: Alejandro Gervasio
Rating: starstarstarstarstar / 14
June 01, 2005

print this article



Armed with the ready class, it’s rather simple to setup an example in order to see how it can be implemented. As you might guess, the following example shows a possible usage of the class:

// include MySQLConnector class
require_once 'mysqlclass.php';

// instantiate a new object from MySQLConnector class
// build the query
$sql='SELECT name FROM table';
// perform query
// display results
    // display values from a "name" table field
    echo $row['name'].'<br />';

echo 'Number total of records returned: '.$db->getNumRows();

From the above example, we can clearly see that connecting to MySQL, selecting a database, and displaying some results after performing a SELECT statement, is a breeze. Indeed, the code speaks by itself, simply because we really know what’s happening in each line. What’s more, the code is extremely portable for being easily plugged into another applications. What more can we ask for?

To Wrap It Up...

In this second part of the series, we’ve progressively developed a MySQL abstraction class, handy to manage database operations following an object-oriented approach. However, in order to implement aggregation in PHP, we need to have at hand another class, right? Well, in the next part we’ll build up a paging class, as the perfect complement for establishing the proper object interaction and show how aggregation can be used with these two functional classes.

Of course, as usual, feel free to use the above class to expand your own horizons in object-oriented programming and have some fun tweaking the code. See you in the next part!

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