diff --git a/wire/core/WireDatabasePDO.php b/wire/core/WireDatabasePDO.php index 28b2ae28..270c7bf5 100644 --- a/wire/core/WireDatabasePDO.php +++ b/wire/core/WireDatabasePDO.php @@ -319,6 +319,21 @@ public function __get($key) { public function closeConnection() { $this->pdo = null; } + + /** + * Tries to query the db and if it fails tries to reconnect + * @return boolean + */ + public function ping() { + try { + $this->pdo->query('SELECT 1'); + } catch (PDOException $e) { + //force reconnect + $this->closeConnection(); + $this->pdo(); + } + return true; + } /** * Retrieve new instance of WireDatabaseBackups ready to use with this connection @@ -346,3 +361,4 @@ public function backups() { } } +