PHP
  Home arrow PHP arrow Page 4 - Caching Result Sets in PHP: Object Interaction Within a Caching System
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

Caching Result Sets in PHP: Object Interaction Within a Caching System
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 5
    2005-10-17


    Table of Contents:
  • Caching Result Sets in PHP: Object Interaction Within a Caching System
  • The first link in the caching process: looking at the “Cache” class
  • The second link in the caching process: overview of the “MySQL” class
  • The third link in the caching process: a quick look at the “Result” class
  • Chaining the links: putting the classes together

  • 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


    Caching Result Sets in PHP: Object Interaction Within a Caching System - The third link in the caching process: a quick look at the “Result” class
    ( Page 4 of 5 )

    Very often it is much better to delegate the responsibility for manipulating database result sets to a separated class, rather that assigning these tasks to the same class that connects to MySQL. That’s the primary reason for the existence of the “Result” class. However, don’t be concerned about it. It only takes care of fetching data, counting table rows and other result-related operations.

    Here is the proper list for the “Result” class:

    class Result{
                var $mysql; // instance of MySQL object
                var $result; // result set
                // constructor
                function Result(&$mysql,$result){
                            $this->mysql=&$mysql;
                            $this->result=$result;
                }
                // fetch row
                function fetchRow(){
                            return mysql_fetch_array($this-
    >result,MYSQL_ASSOC);
                }
                // count rows
                function countRows(){
                            if(!$rows=mysql_num_rows($this->result)){
                                       $this->mysql->isError('Error
    counting rows');
                            }
                            return $rows;
                }
                // count affected rows
                function countAffectedRows(){
                            if(!$rows=mysql_affected_rows($this-
    >mysql->conId)){
                                       $this->mysql->isError('Error
    counting affected rows');
                            }
                            return $rows;
                }
                // get ID from last inserted row
                function getInsertID(){
                            if(!$id=mysql_insert_id($this->mysql-
    >conId)){
                                       $this->mysql->isError('Error
    getting ID');
                            }
                            return $id;
                }
                // seek row
                function seekRow($row=0){
                            if(!mysql_data_seek($this->result,$row)){
                                       $this->mysql->isError('Error
    seeking data');
                            }
                }
    }

    Although the methods belonging to the above class might be appended to the MySQL class, it’s much more efficient having a separated structure that accomplishes all of the row-related operations. So, as you can see, this class allows us to fetch rows, count result rows, and even get the ID from the last inserted record.

    Of course, more methods may be eventually added, useful for improving the functionality within the class. But, as I said before, we’ll keep it simple.

    By this point, we’ve covered in detail each class that interacts with “Cache.” The next step is putting all of the pieces together and demonstrating a practical example.



     
     
    >>> More PHP Articles          >>> More By Alejandro Gervasio
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





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