PHP
  Home arrow PHP arrow Page 4 - Setting up the Foundation for an Exten...
Dev Shed Forums 
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 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
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

Setting up the Foundation for an Extensible Website Engine with PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 14
    2006-10-24

    Table of Contents:
  • Setting up the Foundation for an Extensible Website Engine with PHP 5
  • Defining the core structure of a simple yet dynamic website
  • Creating a simple template file
  • Defining the database schema with MySQL

  • 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


    Setting up the Foundation for an Extensible Website Engine with PHP 5 - Defining the database schema with MySQL


    (Page 4 of 4 )

    Since the previous section was dedicated to demonstrating the complete process for creating the pair of files that put the presentation layer to work, the current one will be focused on defining the simple database schema which will be used for storing the contents of each dynamic web document.

    With reference to the above concept, first I'll create a single database table called "pages" where each row will store web page data. It will be structured as follows: page id, page title, header contents, left column contents, center column contents, right column contents, and finally footer contents.

    As you'll realize, the previous schema is extremely simple to implement, and certainly can be translated to real SQL code by the following statement:

    CREATE TABLE 'pages' (
      'id' INTEGER(4) NOT NULL AUTO_INCREMENT,
      'title' VARCHAR(45) NOT NULL DEFAULT '',
      'header' TEXT NOT NULL DEFAULT '',
      'leftcol` LONGTEXT NOT NULL DEFAULT '',
      'centercol' LONGTEXT NOT NULL DEFAULT '',
      'rightcol' LONGTEXT NOT NULL DEFAULT '',
      'footer' TEXT NOT NULL DEFAULT '',
      PRIMARY KEY(`id`)
    )
    ENGINE = InnoDB;

    Now that the above "pages" database table has been properly created, I'll do something more useful with it. I'm going to fill it up with some basic data to create the contents of all the web site sections that I showed you previously. How will this be done? That's as simple as running the following SQL INSERT statements:

    INSERT INTO pages (id,title,header,leftcol,centercol,rightcol,footer) VALUES
    (NULL,'HomePage','Content of header section goes here','Content
    of left column goes here','Content of main section goes
    here','Content of right column goes here','Content of footer
    section goes here');

    INSERT INTO pages (id,title,header,leftcol,centercol,rightcol,footer) VALUES(NULL,'
    Profile Page','Content of header section goes here','Content of
    left column goes here',' Content of main section for profile page
    goes here','Content of right column goes here','Content of footer
    section goes here');

    INSERT INTO pages (id,title,header,leftcol,centercol,rightcol,footer) VALUES(NULL,'
    Products Page','Content of header section goes here','Content of
    left column goes here',' Content of main section for products
    page goes here','Content of right column goes here','Content of
    footer section goes here');

    INSERT INTO pages (id,title,header,leftcol,centercol,rightcol,footer) VALUES(NULL,'
    Services Page','Content of header section goes here','Content of
    left column goes here',' Content of main section for services
    page goes here','Content of right column goes here','Content of
    footer section goes here');

    INSERT INTO pages (id,title,header,leftcol,centercol,rightcol,footer) VALUES(NULL,'
    Customers Page','Content of header section goes here','Content of
    left column goes here','Content of main section for products page
    goes here','Content of right column goes here'','Content of
    footer section goes here');

    INSERT INTO pages (id,title,header,leftcol,centercol,rightcol,footer) VALUES(NULL,'
    Contact Page','Content of header section goes here','Content of
    left column goes here',' Content of main section for contact page
    goes here','Content of right column goes here','Content of footer
    section goes here');

    Okay, as shown above, the previous six INSERT statements populate the corresponding "pages" database table with some basic data that belong to each one of the website's sections. Following this schema, you can see that every web page now contains a concrete title, and some descriptive texts for the respective header and footer areas, as well as for the pertinent columns. Wasn't that easy?

    Now that the "pages" database table has been filled with information related to each particular section of the website in question, it should be clear to you how to construct a simple application with PHP that fetches data from the mentioned table and injects it straight into the previous template file.

    And best of all, this process can be performed with a unique "pageid" parameter! Definitely, we're on the right way to constructing a  simple yet efficient website engine with PHP. But, to see how this will be done, you'll have to wait till the next tutorial.

    Wrapping up

    In this first article of the series, I introduced the key points for how to build an extensible website engine with PHP 5. More specifically, I developed a comprehensive presentation layer, in conjunction with the respective data layer. However, as I mentioned before, there's a missing piece in this puzzle: the PHP-based application, which will be developed in the next part. Thus, you won't want to miss it!


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · If you're taking your first steps on building dynamic websites with PHP, hopefully...
       · Though I understand the goals of this tutorial, and that it is more of a beginner...
       · Thank you for your extensive comments on my PHP article. As I said in the...
       · Hi, Nice article.Shouldn't there be a part where you pull data from the mysql...
       · Hello Robert,Thank you for the kind comment on my PHP article. You're correct...
       · Here is a more advanced version of a site...
       · Thank you for the contribution. Yes, I've read that series of articles too and...
     

       

    PHP ARTICLES

    - Validating Web Forms with the Code Igniter P...
    - Output Buffering
    - Paginating Database Records with the Code Ig...
    - HTTP Headers in Web Development
    - Project Management: Administration
    - Building a Database-Driven Application with ...
    - User Authentication for a Project Management...
    - Introduction to the CodeIgniter PHP Framework
    - Adding Users for a Project Management Applic...
    - Migrating Class Code for a MIME Email to PHP...
    - Login and Logout Authentication for a Projec...
    - Composing Messages in HTML for MIME Email wi...
    - Project Management: Authentication
    - A Better Way to Determine MIME Types for MIM...
    - Project Management Overview





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway