• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DB reconnect failed

#1
I'm writing a data monitor script work with CLI this week,
Code:
$this->load->database();

#####################################
running 10mins, and local ip changed.
#####################################

// need re-connnect database
$this->db->reconnect();

var_dump($this->db->conn_id)

// bool(false);

$this->db->select('name')->where_in('id', $array)->get('table')->result_array();

// Severity: error --> Exception: Call to a member function real_escape_string() on boolean path\system\database\drivers\mysqli\mysqli_driver.php 344

OK, it's looks like the re-connect was failed.

Why does this error occur? How to deal with it?
Reply

#2
Resolved;
Code:
$this->db->reconnect();

// Replace with:

$this->db->close();
$this->db->initialize();
Reply

#3
In the mysqli driver, reconnect() uses mysqli::ping(), which will attempt to reconnect to the server if the mysqli.reconnect option is enabled on the server. In any case, after calling $this->db->reconnect(), you should check whether $this->db->conn_id is false before attempting to use the connection. If it is false, you could attempt to close/initialize as you did, but you should check the return value of initialize() before attempting to use the connection (as it will return false if it fails to connect/initialize).
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.