【问题标题】:Codeigniter MySQL Call to a member function real_escape_string() on booleanCodeigniter MySQL 在布尔值上调用成员函数 real_escape_string()
【发布时间】:2019-01-29 08:57:12
【问题描述】:

当其他一些进程在执行过程中需要一些时间时,MySQL 查询失败,我称该查询失败了一段时间。当我开始查询时,这里永远不会失败是我的模型 model_common

function get_where_custom($table, $column, $value) {
    $this->db->where($column, $value);
    $query = $this->db->get($table);
    return $query;
}

//这是我的控制器

 function _get_where($table, $query = array(), $select = "*",$limit = NULL, $offset = NULL, $order_by = 'id', $order_as = 'desc')
{

    $this->load->model('model_common');
    if( $this->db->conn_id->ping() == FALSE){
          $this->model_common->reconnect();
    }

        $query = $this->model_common->get_where($table, $query, $select, $limit, $offset , $order_by, $order_as);
        return $query;
}

【问题讨论】:

标签: php mysql codeigniter


【解决方案1】:

可以调用model,但是你也可以调用$this->db(我正在开发CodeIgniter 3.2):

$this->db->reconnect()

但是在驱动程序上你应该修复 reconnect() 函数添加“$this->initialize()”,因为函数 _escape_str 不会尝试重新连接并尝试直接调用 $this->conn_id->real_escape_string (并且 $this->conn_id 重新连接后为 FALSE ):

public function reconnect()
{
    if ($this->conn_id !== FALSE && $this->conn_id->ping() === FALSE)
    {
        $this->conn_id = FALSE;
    }

    //fix
    $this->initialize();
}

【讨论】:

    【解决方案2】:

    像这样更改您的代码:

    $this->model_common->reconnect(); if( $this->db->conn_id === FALSE){ $this->db->initialize(); }

    【讨论】:

    • 您好,KAI,请考虑解释一下您到底做了什么,或者至少解释一下您的代码做了什么,以便阅读代码的人了解您在做什么。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2016-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多