本文介绍了mysql_escape_string()函数已弃用,请使用mysql_real_escape_string()Codeigniter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在服务器上运行的codeigniter中运行Web应用程序.在这里,我有一个用户注册表格,该表格可以在localhost正常运行.但是当涉及到服务器时,当我尝试注册用户时,我的页面显示错误:

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

我尝试更改mysql_driver页面,但更改后一切空白.谁能帮我解决这个错误?

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

推荐答案

如果您使用的是PHP 5.4,则不建议使用mysql_escape_string()函数.因此,您需要在mysql驱动程序文件中进行一些更改.转到system \ database \ drivers \ mysql \ mysql_driver.php并找到escape_str函数,并将函数代码替换为以下代码:

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...

这篇关于mysql_escape_string()函数已弃用,请使用mysql_real_escape_string()Codeigniter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 07:28