This is why you should create a whole different config page where it holds details of how to connect which include the :
Database Name :
Database Server :
Database Username :
Database Password :
which should be in the configuration file and then create another file that includes
the way to connect using the given variables through config.php
So what you shoudl do is create a config.php with the variables to connect to the database while making another file called db.php where it reads the database variables from there and connects that way
here is an example
config.php
PHP:
$db_server = 'localhost';
$db_name = 'database name';
$db_user = 'database user';
$db_passwd = 'database password ';
and db.php(code partially borrowed from SMF)
PHP:
$db_connection = @mysql_connect($db_server, $db_user, $db_passwd);
if (!$db_connection || !@mysql_select_db($db_name, $db_connection))
{
die (mysql_error());
}