PHP
  Home arrow PHP arrow Page 4 - PHP Datastorage Class (continued)
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? 
Google.com  
PHP

PHP Datastorage Class (continued)
By: Chris Root
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 5
    2005-11-21


    Table of Contents:
  • PHP Datastorage Class (continued)
  • Utility Methods
  • The Output Methods in Depth
  • A Snack for the Road

  • 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


    PHP Datastorage Class (continued) - A Snack for the Road
    ( Page 4 of 4 )

    Finally, if you are going to use cookies to store data, the constructor method should have the following code in it at the last If block.

    else if($mode == "c")
    {
          if(isset($_COOKIE[$this-dataname]))
          {
                $this->items = unserialize($_COOKIE[$this->dataname]);
          }
          else
          {
                setcookie($this->dataname);
          }
    }

    If the cookie is not yet set, then it is set, otherwise we retrieve the data from it just as we would with any of the other storage methods. This code simply sets a cookie by the default or the name specified. If you wish to supply additional parameters, such as expiration time, these optional arguments would need to be added to the constructor. You might also want to provide a backup plan in case the user has cookies disabled.

    Wrapping it Up

    Because all of this functionality is wrapped in a class, it can be included and extended by other classes easily.You can then let the err method do the work. You can also have multiple instances of the datastore in a document. Adding database connection capability through an abstraction class would give you a complete data storage solution, and the datastore could be used to provide preset connections and queries. If you come up with a good use make sure to share it.



     
     
    >>> More PHP Articles          >>> More By Chris Root
     

       

    PHP ARTICLES

    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - 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





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek