私は2つのデータベースサーバーDRCと本番サーバーを持っています..
PHP構成ファイルを本番サーバーのIPに接続してデータベースに接続し(正常に動作しています)、本番データベースが接続されていない、選択されていない、または削除されている場合はifステートメントを作成し、DRCサーバーに接続してデータベースを取得しました.
以下のコードは、このアクションを実行します。ローカル ホストで 2 つのデータベースを切り替える場合は正常に動作しますが、本番データベースが利用できない場合、DRC データベースに接続されません。
//Production constants
defined ('DB_SERVER')? null : define ("DB_SERVER" , "20.20.10.1");
defined ('DB_USER') ? null : define ("DB_USER" , "root");
defined ('DB_PASS') ? null : define ("DB_PASS" , "rootpass");
defined ('DB_NAME') ? null : define ("DB_NAME" , "dbname");
//DRC constants
defined ('DB_SERVER_DRC')? null : define ("DB_SERVER_DRC" , "20.20.10.2");
defined ('DB_USER_DRC') ? null : define ("DB_USER_DRC" , "root");
defined ('DB_PASS_DRC') ? null : define ("DB_PASS_DRC" , "rootpass");
defined ('DB_NAME_DRC') ? null : define ("DB_NAME_DRC" , "dbname");
function __construct() {
$this->open_connection();
}
public function open_connection() {
$this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS);
if (!$this->connection) {
$this->open_connection_DRC();
} else {
$db_select = mysql_select_db(DB_NAME, $this->connection);
if (!$db_select) {
$this->open_connection_DRC();
}
}
}
public function open_connection_DRC() {
$this->connection = mysql_connect(DB_SERVER_DRC, DB_USER_DRC, DB_PASS_DRC);
if (!$this->connection) {
die("Database connection failed: " . mysql_error());
} else {
$db_select = mysql_select_db(DB_NAME_DRC, $this->connection);
if (!$db_select) {
die("Database selection failed: " . mysql_error());
}
}
}
それを行うための解決策またはその他の方法、あなたの肯定的な反応を待っています。