How do i solve this error? Deprecated: mysql_escap

2019-05-10 06:09发布

问题:

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

        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

回答1:

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 :)

you are mixing Between mysqli and mysql .

EDIT: from your second error.

  mysqli_real_escape_string ($link ,$source )  // $link is your connection variable

ref



回答2:

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.