我无法连接到位于 dotCloud 上的数据库。我试过了:
$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 (net::ERR_EMPTY_RESPONSE):服务器关闭连接但未发送任何数据。”
我使用以下内容在 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>";
}
我究竟做错了什么?