我正在使用面向对象的MySQLi连接我的数据库。我已经检查了我的凭据,一切都准备就绪。
$mysqli = new mysqli(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DB) or die('There was a problem connecting to the database.');
if (mysqli_connect_errno()) {
printf("Can't connect to MySQL Server. Errorcode: %s\n", mysqli_connect_error());
exit;
}
if ($result = $mysqli->query('SELECT * FROM places WHERE place_id=' . mysql_real_escape_string($_GET['id']))) {
while( $row = $result->fetch_assoc() ){
printf("%s (%s)\n", $row['name'], $row['place_id']);
}
$result->close();
}
$mysqli->close();
这段代码出现了一个错误:
Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access
denied for user '-removed-'@'localhost' (using password: NO) in
/var/www/vhosts/communr.com/httpdocs/pbd/places.php on line 396
Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to
the server could not be established in
/var/www/vhosts/communr.com/httpdocs/pbd/places.php on line 396
我无法弄清楚为什么会出现这些错误。最近我更换了服务器,查询之前我正在建立SQL连接。
你们认为我的新服务器可能出现了一些设置问题吗?
谢谢!
'SELECT * FROM places WHERE place_id="' . mysql_real_escape_string(1354) . '"'
就会出错,但如果我执行'SELECT * FROM places WHERE place_id="1354"'
就能得到预期的结果。 - ATLChris