Home arrow PHP arrow Page 5 - Easy Application Configuration With patConfiguration

Version Control - PHP

Tired of handcrafting configuration file manipulation tools for your Web application? Save yourself some time with patConfiguration, a PHP class designed to assist developers with reading, writing and maintaining application configuration files.

TABLE OF CONTENTS:
  1. Easy Application Configuration With patConfiguration
  2. Plug And Play
  3. Your Friendly Neighbourhood Spiderman
  4. Anatomy Class
  5. Version Control
  6. The Write Stuff
  7. Speaking Native
  8. Not Your Type
  9. When Time Is Money, Recycle!
  10. Cache Cow
  11. Link Zone
By: Vikram Vaswani, (c) Melonfire
Rating: starstarstarstarstar / 1
January 29, 2003

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
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
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: