PHP
  Home arrow PHP arrow Building a Site Engine with PHP, Part 2
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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: starstarstarstarstar / 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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT