Page 1 of 1

questions about config.php

Posted: Thu Apr 12, 2007 1:32 am
by PHPycho
Hello forums
We all know its effective to create one central config file say "config.php"
that contains the required configuration variables .
I had seen the configuration is done by three ways
1> By simply using variables ex $dbHost = ""; etc
2> By using associative arrays ex $setting['dbHost'] = ""; etc
3> By defining constants ex define("DB_HOST",""); etc

My Question ?
Which one to use and why in config.php for creating the configuration file?
Thanks in advance to all of you

Posted: Thu Apr 12, 2007 4:17 am
by CoderGoblin
Your forgetting an ini file which can be read by parse_ini_file. I know there has previously been fairly heated debate about this topic... Should constants be used etc previously with different people having lots of different ideas as to using constants etc.

Generally I like the ini file approach as you can easily define parameters in different groupings and process individual groupings as required. An ini file is also more friendly to those people who have never touched php and need to change something. Saying that I sometimes use a phpvars file containing common variables used throughout the system which I simply include. This file however generally contains parameters which are never going to change even for a new installation.

Posted: Thu Apr 12, 2007 7:32 am
by Maugrim_The_Reaper
Using an array like $settings would generally be the most useful and safe. Constants are global data so they are more likely to be accessible from anywhere (not always a good idea). It's generally recommended to unset database credentials from any config variables after you've finished using them also.