6

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?

6
  • have you tried updating codeigniter Commented Jan 10, 2015 at 5:42
  • both functions deprecated use mysqli_* Commented Jan 10, 2015 at 5:44
  • I'm using latest version of codeigniter Commented Jan 10, 2015 at 5:45
  • Seems you have different versions of php installed locally and on the server. Or your debug settings might be different. Your local environment could be more relaxed when it reports warnings. Commented Jan 10, 2015 at 5:47
  • 1
    instead of mysql_real_escape_string($email) please use $this->db->escape($email); Commented Jan 10, 2015 at 5:48

1 Answer 1

9

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.'_'),
      $str);
  }

  return $str;
 }

It may help you...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.