我無法連接到我的數據庫駐留在dotCloud。我想:如何使用php(託管在dotCloud上)連接到遠程mysql數據庫
$mysqli = new mysqli($db_host, $db_user, $db_password, $db_name);
和
$mysqli = mysqli_connect($db_host, $db_user, $db_password, $db_name);
和
$mysqli = new mysqli($remote_server, $db_user, $db_password, $db_name);
和
$mysqli = mysqli_connect($remote_server, $db_user, $db_password, $db_name);
,但連接失敗,我也得到「錯誤324(淨值:: ERR_EMPTY_RESPONSE):服務器關閉沒有sendin的連接g任何數據。「
我找回動態上面下面的mysqli的腳本變量:
$env = json_decode(file_get_contents("/home/dotcloud/environment.json"));
$db_user = $env->DOTCLOUD_DB_MYSQL_LOGIN;
$db_password = $env->DOTCLOUD_DB_MYSQL_PASSWORD;
$db_host = $env->DOTCLOUD_DB_MYSQL_HOST;
$db_port = $env->DOTCLOUD_DB_MYSQL_PORT;
$remote_server = '$db_host:$db_port';
//I also define $db_name here
$db_name = 'mydbname';
我也有mysqli的腳本下面的下面的代碼:
if (mysqli_connect_error()) {
die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error());
$result["status"] = "failed";
$result["message"] = "Failed to connect to database.";
echo json_encode($result);
exit;
} else {
// Successfully connected!
$stmt = $mysqli->stmt_init();
echo "<p>Successfully connected!!</p>";
}
我在做什麼錯?
您的$ db_name變量在哪裏? – Stepo 2013-03-02 01:07:09
@Stepo,我編輯了上面的代碼以顯示我定義$ db_name的位置。 – Naomi 2013-03-02 03:26:47