Skip to content

Commit

Permalink
Check $_connection is not null before trying to use it
Browse files Browse the repository at this point in the history
Stops a fatal error if calling isConnected() after disconnect().
  • Loading branch information
graemetait committed Sep 21, 2015
1 parent 8fae10a commit 1b33efa
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/Cake/Model/Datasource/DboSource.php
Expand Up @@ -857,10 +857,14 @@ public function name($data) {
* @return bool True if the database is connected, else false
*/
public function isConnected() {
try {
$connected = $this->_connection->query('SELECT 1');
} catch (Exception $e) {
if (is_null($this->_connection)) {
$connected = false;
} else {
try {
$connected = $this->_connection->query('SELECT 1');
} catch (Exception $e) {
$connected = false;
}
}
$this->connected = ! empty($connected);
return $this->connected;
Expand Down

0 comments on commit 1b33efa

Please sign in to comment.