0

MySQL query fails when some other process takes some time in execution of process i call the query it fails some time. when i start query in the beginning never fails here is my model model_common

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

//here is my controller

 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;
}
Mehul Kuriya
  • 608
  • 5
  • 18

2 Answers2

1

It's ok to call on model, but you can also call on $this->db (I'm working on CodeIgniter 3.2):

$this->db->reconnect()

But on the driver you should fix the reconnect() function adding "$this->initialize()", because the function _escape_str don't try to reconnect and try to call $this->conn_id->real_escape_string directly (and $this->conn_id is FALSE after reconnect ):

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

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

change your code like this:

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

KAI
  • 1
  • Hi KAI, please consider explaining what exactly you've done, or minimally provide an explanation of what your code does so that people who read the code understand what you're doing exactly. Thanks! – VIISHRUT MAVANII May 15 '19 at 10:35