不推荐使用mysql_escape_string()函数使用mysql_real_escape_string()Codeigniter

时间:2015-01-10 05:40:47

标签: mysql codeigniter

我正在运行在服务器上的codeigniter中运行一个Web应用程序。这里我有一个用户注册表单,在localhost中工作正常。但是当谈到服务器时,当我尝试注册用户时,我的页面会显示错误:

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

我尝试更改我的mysql_driver页面,但更改后的所有内容都变为空白。谁能帮我解决这个错误?

1 个答案:

答案 0 :(得分:9)

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

/**
  * 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;
 }

它可能对你有帮助......