Let me instantly change my database connection configurations on the per-vhost basis, to ensure that I do not have to edit any PHP code because it moves from staging to reside but access different databases. This really is on one devoted server.

So I'm wondering, can one set a PHP variable or constant in httpd.conf included in the vhost definition the site may then use to suggest itself to some testing database instantly?

$database = 'live';
if (some staging environment variable is true) {
    $database = 'testing'; // and not live
}

If the is not possible, I suppose within this situation I'm able to securely examine the hostname I am running onto tell, but I would like something rather less fragile

Hope this will make sense

thank you

Ian

Yep...this can be done:

SetEnv DATABASE_NAME testing

after which in PHP:

$database = $_SERVER["DATABASE_NAME"];

or

$database = getenv("DATABASE_NAME");

Have you attempted to make use of the .htaccess file? You can override the php.ini values utilizing it.

Just place the .htaccess file to your htdocs directory:

php_value name value

Futher information:

You are able to set an atmosphere variable and retrieve it with PHP.

In httpd.conf:

SetEnv database testing

Inside your PHP:

if (getenv('database') == 'testing') I wouldn't set an atmosphere variable, because this is also visible in arrears script results like PhpInfo()

only use a php_value inside your .htaccess just over the htdocs folder and you are done and safe :)