也許我沒有正確理解你,但你可以創建一個配置值的數組,按優先級順序,嘗試建立數據庫連接的循環,並在連接建立後跳出循環。例如(使用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