当我尝试更新数据库中的数据时,出现此错误。 这是我的database.php 文件
<?php
$db_name = "db";
$db_server = "localhost";
$db_user = "xxxx";
$db_pass = "zzzzzzzzz";
$mysqli = new MySQLi($db_server, $db_user, $db_pass, $db_name)
or die(mysqli_error());
?>
更新.php
<?php
require 'database.php';
$title = mysql_real_escape_string($_POST['title']);
$id = mysql_real_escape_string($_POST['id']);
$update_query = "UPDATE photos SET title = '$title' WHERE id='$id'";
$result = $mysqli->query($update_query) or die(mysqli_error($mysqli));
if ($result) {
echo "Success!";
echo "The title of this photo has been changed to: <strong>$title</strong>";
}
?>
错误信息:
Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\wamp\www\myPhotosWebsite\changePhotoTitle.php on line 5
最佳答案
您正在混合过程式调用和面向对象式调用。
尝试:
$title = $mysqli->escape_string(_POST['title']); /* Call as a method */
而不是:
$title = mysql_real_escape_string($_POST['title']);
real_escape_string
需要有效的连接句柄,因为它需要知道连接字符集。
如果将其作为过程调用,则应将连接句柄作为第一个参数传递:
mysql_real_escape_string($connection_handle, $string_to_escape)
或者只是将其作为如上所述的方法调用。
参见mysqli_real_escape_string
了解更多详情
关于mysql - 更新时出现“ODBC”@'localhost' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/724921/