In your regular php scripts:
include('login.inc');
In 'login.inc':
<?php
include('mode.inc'); // defines $dbname, $dbuser, $dbpass
if (! ($dbid = mysql_connect($dbname, $dbuser, $dbpass)))
header('Location: /bad_db.php');
?>
Now, in your real database directory, e.g.:
/www/ht_docs/live
you have a copy of 'mode.inc' that points to the live database, whereas in
/www/ht_docs/test
you have one that logs into the test database. When you want to promote "test" to "live", you simply copy /www/ht_docs/live/mode.inc to a safe place, copy all of ./test to ./live, and then put back the original 'mode.inc'. Bingo: all your new code is now running against the live database. Plus, this method integrates will with CVS (you can have scripts do the promotion, etc), and it can be extended to further levels--e.g. each developer can have their own sandbox directory (with a corresponding copy of the database) and then 'test' is a more formal "validation" copy run by your testing department.
The key is to centralize that decision about which database to connect to inside one tiny include-file that contains nothing else.