Maybe I did not understand you correctly, but you can just create an array of config values, in order of priority, loop over trying to establish a database connection, and jump out of the loop once a connection has been established. For example (using MySQLi):
$db_config = array(
// Try this first.
array(
'host' => 'xxxxx.xxxxx.xxxx',
'user' => 'xxxx_xxxx',
'pass' => 'xxxxx',
'db' => 'xxxxx_s'
),
// Then this.
array(
'host' => 'localhost',
'user' => 'root',
'pass' => '',
'db' => 'edoctor_s'
)
// ...
);
$connection = null;
foreach ( $db_config as $config ) {
$connection = mysqli_connect( $config[ 'host' ], $config[ 'user' ], $config[ 'pass' ], $config[ 'db' ] );
// No need to keep looping if we have a valid connection.
if ( ! mysqli_connect_error() )
break;
else
$connection = null;
}