We define an environment variable (ENVPHP), and use this in our XML configuration files, so the correct DB parameters are loaded as long as you define the correct ENVPHP environment variable. Using XML you can extend (or override) your common parameters with those for the specific environments.
ie. the configuration looks as follows :
<?xml version="1.0" encoding="UTF-8"?>
<application>
<common>
<name>MyApp_name</name>
<code>MyApp_code</code>
<version>MyApp_version</version>
<authentication>
... authentication specific parameters (ie. LDAP connection parameters)
</authentication>
...
</common>
<dev extends="common">
<database>
... DB connection parameters for development
</database>
...
</dev>
<tst extends="common">
<database>
... DB connection parameters for test
</database>
...
</tst>
<prd extends="common">
<database>
... DB connection parameters for production
</database>
...
</prd>
</application>
And to load the configuration, I have the following in my bootstrap (well, actually in an Application singleton class) :
public static function getEnv()
{
if (self::$env === null) {
self::$env = getenv('ENVPHP');
} else {
return self::$env;
}
}
protected function initConfig ()
{
$configFile = $this->appDir . '/config/application.xml';
if (! is_readable($configFile)) {
throw new Application_Exception('Config file "' . $configFile . '" is not readable');
}
if (false === self::getEnv()) {
throw new Application_Exception('The environment variable "ENVPHP" is not defined');
}
$config = new Zend_Config_Xml($configFile, self::getEnv(), true);
$config->setReadOnly();
Zend_Registry::set('config', $config);
$this->config = $config;
}
In PHP code if I want to do some things only for specific environments then I use Application::getEnv() to check what environment I'm in and execute the code I want according to it.
BTW The ENVPHP environment variable can be set in your apache configuration file using ie. SetEnv ENVPHP "dev"
within your VirtualHost container. For CLI PHP scripts you should set it as an OS environment variable...