php 我该如何解决这个错误?已弃用:mysql_escape_string():此函数已弃用;使用 mysql_real_escape_string() 代替
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23725040/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do i solve this error? Deprecated: mysql_escape_string(): This function is deprecated; use mysql_real_escape_string() instead
提问by FlikFlak
I get stuck on the following:
我陷入了以下问题:
Deprecated: mysql_escape_string(): This function is deprecated; use mysql_real_escape_string() instead. in /home/xtremeso/public_html/mp3/includes/class/_class_mysql.php on line 116
已弃用:mysql_escape_string():此函数已弃用;使用 mysql_real_escape_string() 代替。在第 116 行的 /home/xtremeso/public_html/mp3/includes/class/_class_mysql.php
function safesql( $source )
{
if ($this->db_id) return mysqli_real_escape_string ($this->db_id, $source);
else return mysql_escape_string($source);
}
I already tried to mysql_escape_real_string but that doesnt solve the issue. And ignoring php error messages via .htacces file doesnt work either
我已经尝试过 mysql_escape_real_string 但这并没有解决问题。通过 .htacces 文件忽略 php 错误消息也不起作用
回答by echo_Me
the error message clearly said it .
错误信息清楚地说明了这一点。
change this
改变这个
else return mysql_escape_string($source); // you are using mysql here
to
到
else return mysqli_real_escape_string($source); //will be mysqli
OBS: you should switch to PDO or MYSQLI as MYSQL mysql_real_escape_string
will also be deprecated :)
OBS:您应该切换到 PDO 或 MYSQLI,因为 MYSQLmysql_real_escape_string
也将被弃用 :)
you are mixing Between mysqli and mysql .
你在 mysqli 和 mysql 之间混合。
EDIT: from your second error.
编辑:来自您的第二个错误。
mysqli_real_escape_string ($link ,$source ) // $link is your connection variable
回答by Sourabh
you need to connect mysql to the database before you use mysql_real_escape_string, this function doesn't work without mysql being connected to database.
在使用mysql_real_escape_string 之前需要先将mysql 连接到数据库,如果没有mysql 连接到数据库,此功能将不起作用。