PHP
  Home arrow PHP arrow Page 5 - Easy Application Configuration With pa...
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

Easy Application Configuration With patConfiguration
By: Vikram Vaswani, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2003-01-29

    Table of Contents:
  • Easy Application Configuration With patConfiguration
  • Plug And Play
  • Your Friendly Neighbourhood Spiderman
  • Anatomy Class
  • Version Control
  • The Write Stuff
  • Speaking Native
  • Not Your Type
  • When Time Is Money, Recycle!
  • Cache Cow
  • Link Zone

  • 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


    Easy Application Configuration With patConfiguration - Version Control


    (Page 5 of 11 )

    Let's now consider a variant of the example on the previous page, this one printing the value of a single configuration variable:



    <? // include class require("patConfiguration.php"); // create patConfiguration object $conf = new patConfiguration; // set config file locations $conf->setConfigDir("config"); // read config file $conf->parseConfigFile("config.xml"); // get configuration values print_r($conf->getConfigValue("application.version")); ?>
    In this case, since the getConfigValue() method receives the path and name of the configuration value to be retrieved, only that value is retrieved and printed.

    Here's a more realistic example, this one using an XML configuration file containing MySQL database access parameters

    <?xml version="1.0" encoding="UTF-8"?> <configuration> <path name="mysql"> <configValue name="host" type="string">localhost</configValue> <configValue name="user" type="string">joe</configValue> <configValue name="pass" type="string">secret</configValue> <configValue name="db" type="string">db456</configValue> </path> </configuration>
    to open up and use a database connection.

    <? // include class require("patConfiguration.php"); // create patConfiguration object $conf = new patConfiguration; // set config file locations $conf->setConfigDir("config"); // read config file $conf->parseConfigFile("config.xml"); // get and use configuration values $connection = mysql_connect( $conf->getConfigValue("mysql.host"), $conf->getConfigValue("mysql.user"), $conf->getConfigValue("mysql.pass") ) or die ("Unable to connect!"); mysql_select_db( $conf->getConfigValue("mysql.db") ) or die ("Unable to select database!"); $query = "SELECT * FROM users"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); mysql_close($connection); ?>

    More PHP Articles
    More By Vikram Vaswani, (c) Melonfire


     

       

    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 6 hosted by Hostway