也许我没有正确理解你,但你可以创建一个配置值的数组,按优先级顺序,尝试建立数据库连接的循环,并在连接建立后跳出循环。例如(使用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;
}
感谢您的信息。对我的工作感到抱歉。其实我在发帖之前删除了一些字符... – 2013-05-06 04:54:23
并且不会从不好的东西中停止检查一个字符的可能性很低,即使可以手动尝试 – 2013-05-06 04:56:15