PEAR Articles
  Home arrow PEAR Articles arrow Page 4 - Building a Content Management System w...
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
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? 
PEAR ARTICLES

Building a Content Management System with PEAR
By: David Web
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-10-01

    Table of Contents:
  • Building a Content Management System with PEAR
  • The database structure
  • Tables
  • The PEAR::DB connection

  • 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 Content Management System with PEAR - The PEAR::DB connection


    (Page 4 of 4 )

    So where does database abstraction come into play? So far we have been looking only at the database tables and the application structure. Once you've installed the PEAR::DB package, it will be available system wide. This means that you can access it from anywhere. To use DB you simply include it in your scripts and you will have access to all its functions.

    For our site, we want to have a central place where we can make changes that will affect the whole site. I have created a file that will hold all the information that DB requires. This file is called "connx.php." It abstracts database access in the sense that it enables you to use any kind of database system, without actually having to install a specific driver. All that you change is the type of database driver that you prefer in your configuration script (such as connx.php).

    You can see the contents of the connx.php script below:

    <?php


    // the hostname of the database server

    // the username to connect with

    // the user's password

    // the name of the database to connect to

    // the type of database server.

    $dbhost= "localhost";

    $dbuser= "root";

    $dbpass= "pass";

    $dbname= "cms";

    $dbtype= "mysql";


    // Build a DSN string (Data Source Name)

    // Required by DB::connect()

    $dsn = $dbtype . "://"

    .$dbuser . ":"

    . $dbpass . "@"

    . $dbhost . "/"

    . $dbname;


    // Creates a database connection object in $db

    // or, a database error object if it went wrong.

    // The boolean specifies this is a persistent

    // connection like mysql_pconnect(), it

    // defaults to FALSE.

    $db = DB::connect($dsn, TRUE);


    // Check whether the object is a connection or

    // an error.

    // Print out a message and exit if it's

    // an error object.

    if (DB::isError($db)) {

    die($db->getMessage());

    }


    ?>

    In the next article we will look at this code in detail, and also discuss the other application-wide scripts.


    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.

       · This is what pear.php.net says about the DB Package:This package has been...
     

    PEAR ARTICLES ARTICLES

    - Deleting Authors from a PEAR Content Managem...
    - PEAR CMS: Index and Delete Scripts
    - Listing Articles for a PEAR Content Manageme...
    - Building an Authors Page for a PEAR CMS
    - Building the View Details Page in a PEAR CMS
    - Creating the Main Pages of a PEAR CMS
    - Completing the Login Script for a PEAR CMS
    - User Authentication for a PEAR CMS
    - A PEAR CMS: Examining the Code
    - Building a Content Management System with PE...
    - Installing a PEAR Package
    - My PEAR: The Beginning
    - Using XML_RPC2 with PEAR
    - Using Web Service APIs (Amazon and Yahoo!) w...
    - Database Abstraction with MDB2 from PEAR





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