php Deprecated: mysql_real_escape_string(): mysql 扩展被弃用,将来会被移除:使用 mysqli 或 PDO

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22152019/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 04:41:53  来源:igfitidea点击:

Deprecated: mysql_real_escape_string(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO

phpmysqlpdomysqli

提问by Yannick

I'm actually looking for an alternative to mysql_real_escape_string to solve this error. in php 5.4 it worked perfectly but no longer in php 5.5

我实际上正在寻找 mysql_real_escape_string 的替代方案来解决此错误。在 php 5.4 中它运行良好,但不再在 php 5.5 中

$this->mysqli = new mysqli($this->host, $this->user, $this->pass, $this->name);
// in class user
public function __set($p_sProperty, $p_vValue)
        {   
            switch($p_sProperty)
            {    
// this is marked as the error
case "Email":
             $this->Email = **mysql_real_escape_string**($p_vValue); 
                break;
}
}

回答by John Conde

You using MySQLi so use mysqli_real_escape_string():

你使用 MySQLi 所以使用mysqli_real_escape_string()

$this->Email = $this->mysqli->real_escape_string($p_vValue);