Codeigniter MySQL在布尔值上调用成员函数real_escape_string()

时间:2019-01-29 08:57:13

标签: php mysql codeigniter

当某个其他进程在执行过程中需要花费一些时间时,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;
}

2 个答案:

答案 0 :(得分:0)

  

像这样更改代码:

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

答案 1 :(得分:0)

可以调用模型,但您也可以调用 $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();
}