From a7b5f8c3af2398da3f6d0c35b4ac5bf77331468b Mon Sep 17 00:00:00 2001 From: paolo Date: Thu, 6 Aug 2015 16:05:16 +0200 Subject: [PATCH] DboSource now check the actual status of connection by executing a dumb query on DB This change makes it possible for developer to build reconnection logic on MySQL connections which frequently time out in long running CLI processes. Cherry picked onto 2.7 from #7190. --- lib/Cake/Model/Datasource/DboSource.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index 927a6e369..a41e88cef 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -857,6 +857,12 @@ class DboSource extends DataSource { * @return bool True if the database is connected, else false */ public function isConnected() { + try { + $connected = $this->_connection->query('SELECT 1'); + } catch (Exception $e) { + $connected = false; + } + $this->connected = ! empty($connected); return $this->connected; }