Home arrow PHP arrow PHP Datastorage Class

PHP Datastorage Class

Many websites use databases for storing data for use by web applications. There are situations in which this is not the best solution, however. For light, moderate, or temporary storage requirements, you might prefer to use flat files, session variables, and cookies. This article will describe how to create a class that handle all of these. It is the first of two parts.

TABLE OF CONTENTS:
  1. PHP Datastorage Class
  2. Top of the Page
  3. Flat Files
  4. Getting Data In
  5. Getting Data Out
By: Chris Root
Rating: starstarstarstarstar / 10
November 14, 2005

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Web applications need data. Getting data in and out of an application with the minimum amount of code can be a challenge, and it can be rather easy to end up with something that is not portable or reusable in any way.

Many times databases are a natural choice for storing data for use by a web application. If you have ever worked on a site that makes extensive use of a database, however, you likely know the strain it can put on a system. A database isn't always the best solution for light or temporary data storage, so it makes sense to have something else that fits your requirements.

In this article I will guide you through the design of a data storage class that can meet the needs of a long list of web applications requiring light to moderate or temporary storage requirements.

Where Will It All Go?

There are three places we can store data that will be useful to us. These are a flat file, session variables and cookies. The class described here can use all of these. If you were to add some sort of database abstraction class to it, database storage could be used as well.

This class has been used as the core of a number of different applications so far.

• A shopping cart.

• An email and web page hit counter.

• Storage of temporary customer registration information.

• A debugger logger for template based pages.

• A project management system.

• Multi-page form storage.

• Data conversion tool.

There are many more potential uses, and once you finish this article I'm hoping you will have some of your own ideas.



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

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

Dev Shed Tutorial Topics: