DB reconnect failed - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6) +--- Forum: CodeIgniter 3.x (https://forum.codeigniter.com/forumdisplay.php?fid=17) +--- Thread: DB reconnect failed (/showthread.php?tid=63944) |
DB reconnect failed - imwwp - 12-25-2015 I'm writing a data monitor script work with CLI this week, Code: $this->load->database(); OK, it's looks like the re-connect was failed. Why does this error occur? How to deal with it? RE: DB reconnect failed - imwwp - 12-26-2015 Resolved; Code: $this->db->reconnect(); RE: DB reconnect failed - mwhitney - 12-29-2015 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). |