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
questions about config.php
Moderator: General Moderators
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
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.
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.
- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland
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.