zoukankan      html  css  js  c++  java
  • PHP : CodeIgniter mysql_real_escape_string 警告

    版本 CodeIgniter 3 PHP 5.4

    感谢万能的stackoverflow。

    得修改CodeIgniter的源码。

    ./system/database/drivers/mysql/mysql_driver.php

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

    斜体加下划线的就是修改过的部分。

    参考:https://stackoverflow.com/questions/33995279/codeigniter-showing-error-mysql-real-escape-string-expects-parameter-2-to-be

  • 相关阅读:
    opentsdb安装部署
    python发送邮件(html)例子
    python查库写库例子
    获取rds的cpu和内存使用情况
    数据库损坏的情况下如何获取到dbid
    grafana安装升级部署
    Specified key was too long
    mysql动态执行sql批量删除数据
    kafka删除topics
    cratedb导入json文件
  • 原文地址:https://www.cnblogs.com/foxcharon/p/9396192.html
Copyright © 2011-2022 走看看