PHP
  Home arrow PHP arrow Page 5 - Object Interaction in PHP: Introduction to Aggregation, part 2
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Object Interaction in PHP: Introduction to Aggregation, part 2
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 14
    2005-06-01


    Table of Contents:
  • Object Interaction in PHP: Introduction to Aggregation, part 2
  • Fetching data with class: the “MySQLConnector” class
  • Adding Some Functionality to the Class
  • Improving the “MySQLConnector class: adding row-counting methods
  • Implementing the “MySQLConnector” class: a practical example

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Object Interaction in PHP: Introduction to Aggregation, part 2 - Implementing the “MySQLConnector” class: a practical example
    ( Page 5 of 5 )

    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
    $db=&new
    MySQLConnector('localhost','username','password','database');
    // build the query
    $sql='SELECT name FROM table';
    // perform query
    $db->performQuery($sql);
    // display results
    while($row=$db->fetchRow()){
        // 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
     

       

    PHP ARTICLES

    - Using Directory Iterators to Build Loader Ap...
    - Using the spl_autoload() Functions to Build ...
    - Working Out of the Object Context to Build L...
    - Using the _autoload() Magic Function to Buil...
    - The Destruct Magic Function in PHP 5
    - The Autoload Magic Function in PHP 5
    - Developing a Recursive Loading Class for Loa...
    - The Sleep and Wakeup Magic Functions in PHP 5
    - Using the Clone Magic Function in PHP 5
    - Including Files Recursively with Loader Appl...
    - The Call Magic Function in PHP 5
    - Designing a Captcha System with PHP and MySQL
    - Using Static Methods to Build Loader Apps in...
    - The Isset and Unset Magic Functions in PHP 5
    - Advanced PHP Form Input Validation to Check ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT