• 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

  • 相关阅读:
    React-使用combineReducers完成对数据对拆分管理
    Linux
    Linux
    linux
    linux
    Linux
    Linux
    Linux
    Linux
    Linux 系统基础优化和常用命令
  • 原文地址:https://www.cnblogs.com/foxcharon/p/9396192.html
Copyright © 2020-2023  润新知