Aishwaryas Aishwaryas - 1 year ago 278
SQL Question

mysql_escape_string() function is deprecated use mysql_real_escape_string() Codeigniter

I am running a web app in codeigniter running on server. Here I've a user registration form, which works fine in localhost. But when it comes to server,when I try to register an user,my page shows the error:

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

I tried changing my mysql_driver page but after changing everything goes blank. Can anyone help me to solve this error?

Answer Source

If you are using PHP 5.4 the function mysql_escape_string() is deprecated.So you need to do some changes in mysql driver file.Go to system\database\drivers\mysql\mysql_driver.php and find the escape_str function and replace the functions 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.'_'),

  return $str;

It may help you...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download