Mysql_escape_string () function deprecated using mysql_real_escape_string () Codeigniter

I am running a web application in codeigniter running on a server. Here I have a user registration form that works fine in localhost. But when it comes to the server, when I try to register a user, an error is displayed on my page:

mysql_escape_string() function is deprecated use mysql_real_escape_string() in mysql/mysql_driver

I tried changing my mysql_driver page, but after the change, everything went wrong. Can someone help me solve this error?

+6
source share
1 answer

If you are using PHP 5.4, the mysql_escape_string () function is deprecated. Therefore, you need to make some changes to the mysql driver file. Go to the system \ database \ drivers \ mysql \ mysql_driver.php and find the escape_str function and replace the function code with this code:

 /** * Escape String * * @param string * @param bool whether or not the string will be used in a LIKE condition * @return string */ public function escape_str($str, $like = FALSE) { if (is_array($str)) { foreach ($str as $key => $val) { $str[$key] = $this->escape_str($val, $like); } return $str; } $str = is_resource($this->conn_id) ? mysql_real_escape_string($str, $this->conn_id) : addslashes($str); // escape LIKE condition wildcards if ($like === TRUE) { return str_replace(array($this->_like_escape_chr, '%', '_'), array($this->_like_escape_chr.$this->_like_escape_chr, $this->_like_escape_chr.'%', $this->_like_escape_chr.'_'), $str); } return $str; } 

It can help you ...

+9
source

Source: https://habr.com/ru/post/980796/


All Articles