PHP
  Home arrow PHP arrow Building a Site Engine with PHP, Part ...
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 
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

Building a Site Engine with PHP, Part 2
By: James Murray
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 70
    2004-06-14

    Table of Contents:
  • Building a Site Engine with PHP, Part 2
  • Best Site() Ever Made
  • OK, Plug it in Now
  • Module Madness
  • Bring it Together

  • 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


    Building a Site Engine with PHP, Part 2


    (Page 1 of 5 )

    If you read the first article in this series, you’d know that we’re about to start talking about the plug-in and module system for our site engine. Along with the plug-ins and modules, we’re also going to be discussing some of the general functions that are needed to make site engine work correctly.

    Don't Plug it in Yet

    In the last article I discussed briefly how the plug-in and module systems worked. This article will get more in-depth on the subject, but, before we talk about the plug-ins (in fact, before they'll even work) we'll have to make a few other functions. I'd also like to take this time to let you know that for this project we're going to be using PHP5rc2 with MySQL.

    Since all the information about the plug-ins and modules is in the database, we're going to want to make a class that will let us perform the most common SQL functions with ease. Also, since the site engine will run multiple sites, each of which can have their own plug-ins and modules, we'll want to make the functions that let the engine know what site is requesting the plug-ins and modules. Let's get started with our general functions. I hope you learn something new and cool that you'll like.

    This is the SQL class; save the following as:

    "your_site_dir/inc/sql.inc.php"

    <?PHP
    class sql{
       
        public $qcount;    //this keeps count of how many queries we make
       
        function sql(){    //we name the main function the same as the class so that it initializes when the class is called
            $this->qcount=0;    //set the default of $qcount to 0 because we don't yet have any queries
           
    $db=@mysql_connect($host,$user,$pass,$dbname);    //create connection string ready to accept the parameters to connect with
            if($db){    // check to see if a connection is made
                return $db;    //return the connection ID if it's a valid connection
            }else{
                die("<b>Error:</b> Database offline.<br/>".mysql_error() );    //if connection is invalid quit script and return error
            }
        }
       
        function _select_db($dbname){
            return mysql_select_db($dbname);    //this is the function to select a MySQL database (of course...)
        }
       
        function _query($query){
            $this->qcount++;    //add 1 to the $qcount for each query, this will update $qcount everything the _query function is called
            return mysql_query($query);        //This is the function to execute a Query on a MySQL database
        }

        function _fetch_row($id){
            return mysql_fetch_row($id);    //this fetches one row of data from the result of calling the _query function, it returns data as an array with numeric offsets
        }
       
        function _fetch_array($id){
            return mysql_fetch_array($id);    //this function is just like the _fetch_row function, only this on returns both numeric offsets, and offsets named like the database field
        }
       
        function _insert_id(){
            return mysql_insert_id();    //this function returns the ID generated for an AUTO_INCREMENT column by the previous INSERT query
        }
       
        function _affected_rows($id){
            return mysql_affected_rows($id);    //this function returns the number of rows affected by the last INSERT, UPDATE or DELETE query
        }
       
        function _num_rows($id){
            return mysql_num_rows($id);        //this function counts the number of rows returned form a previous SELECT query
        }
       
        function _fetch_object($id){
            return mysql_fetch_object($id);        //This function is my favorite MySQL function, it's just like the _fetch_array function except an object is returned instead of an array
        }
       
        function _mysql_error(){
            return mysql_error();    //This function will return and errors generated by MySQL
        }
           
    }
    ?>

    Now to complement our previous class file, we'll make another little class called config. This should be self explanatory; save the following as "your_site_dir/inc/config.inc.php"

    <?PHP
    class config {
       
        public $dbhost;
        public $dbuser;
        public $dbpass;
        public $dbname;
       
        function config(){
            $this->dbhost="localhost";
            $this->dbuser="root";
            $this->dbpass="";
            $this->dbname="engine";
        }
    }
       
    ?>

    These may not directly tie in to each other at the moment, but they will in just a bit.

    More PHP Articles
    More By James Murray


     

       

    PHP ARTICLES

    - Authentication Scripts for a User Management...
    - Utilizing the Use Keyword for Namespaces in ...
    - Building a User Management Application
    - 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





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