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