PHP
  Home arrow PHP arrow Page 2 - PHP Application Development Part Two
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
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

PHP Application Development Part Two
By: David Fells
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 33
    2005-03-08

    Table of Contents:
  • PHP Application Development Part Two
  • Storing Dynamic Data
  • Error Handling
  • Event Logging

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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 Application Development Part Two - Storing Dynamic Data


    (Page 2 of 4 )

     

    Having established the basic rules for handling configuration, we should now evaluate or options for storing dynamic data in our application. Dynamic data consists of any information that is expected to either change often or be manageable through a Web interface, or both, as is typically the case. In a typical Web application, this would consist of things such as text for Web pages or items to appear in a menu. This could of course be extended to include any sort of data with which your particular application works.

    There are only two options available for storing dynamic data: the filesystem itself or a database. Storing data in a database is by far the most common choice in recent years with the advent of easy to use databases like MySQL. While I use MySQL for nearly every project I build, there are still times where storing data in a file simply makes more sense. There are a few quick questions you can ask yourself if you aren’t sure which is appropriate for your situation.

    1. Will the application need to produce reports comprising aggregate pieces of data from the site?
    2. Will the application need to store meta data for persistent objects?
    3. Will the application need to maintain strong relationships between persistent objects?

    If the answer to any of these questions is yes, then a database is probably the logical choice. Typical justifications for using a database include “this website needs a search tool” or “this website needs to store data in multiple languages.” Oddly enough, neither of these are reasons to use a database, and in the case of storing text in multiple languages a database can often complicate the situation. Web application searching can be achieved with free tools like htdig and multiple languages can be handled simply by good file system orgnization.

    Databases really show their strength in producing aggregate data, storing metadata, and storing logical relationships. It is true that you could build reports from data stored in flat files – after all, that’s how it was done before databases were around – but why reinvent the wheel? SQL provides a consistent semantic method for producing reports; by all means, use it.

    Maintaining metadata is also possible with flat files, either by maintaining a metadata file for each persistent object or by combining the metadata and the actual data into a single file using XML or some custom encoding scheme. Often the best solution is to use a combination of the file system and a database. Consider a system where users should be able to upload images. It is far more efficient to store images in the file system, but storing metadata in the database allows you to normalize your data and search image metadata without clunky text file processing. In the case of a system that stores text documents, it would make sense to store the metadata and the actual text in the database and avoid flat files altogether. This simplifies management, boosts maintainability, and simplifies feature changes such as adding support for versioning, authors, publishing state, and so forth.

    Databases also shine when used to store relationships between persistent objects. SQL allows you to easily build a result set containing individual records for objects spanning multiple tables or even databases without writing a lot of XML parsing code, messy object serialization or even worse, the use of some proprietary encoding scheme. This task can be accomplished in the filesystem with either method, but neither one is robust or elegant. Portability and semantics are completely lost when this sort of information is stored in a serialized or proprietary format, and while XML does maintain the integrity of the data from a semantic standpoint, it fails to provide a simple interface for object retrieval – meaning that you must write a lot of code to properly repopulate and reconstruct objects from XML files.

    The most common solution is to use a combination of the file system and a relational database, especially in cases where binary data storage is a necessity. Performance is only a small consideration in this situation, but more often than not storing information in a database will yield better performance than flat files, as the database already provides an optimized data retrieval layer. Again there is also a measure of personal preference involved, and some people may find working with flat files simpler than working with a database or vice versa. Ultimately, it is important that as a developer you use the best approach possible for the job and mold personal preference around what produces the best results.

    More PHP Articles
    More By David Fells


       · Just wanted to say i am really enjoying these articles. Keep it up.. I am a self...
       · PHP5 has a robust built-in error handling in the form of exceptions. Also the object...
       · I totally agree that an upgrade to PHP 5 is the way to go, unfortunately that's not...
       · If you don't have the money to get your own server (or if your IT department won't...
       · Really enjoying the articles. I have been developing in PHP for about 4 years now...
       · Hi David,A nice couple of articles. I'm looking forward to the next one in this...
       · woops =) proofreading never was my strong suit =)
       · Hi! Im looking forward for your next article.
       · I am waiting for your next article. Thanks for your effort and experience
     

       

    PHP ARTICLES

    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter





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