Skip to content

Commit

Permalink
Fixed consistency of Connection::ping() method with doctrine/dbal:2.5-rc
Browse files Browse the repository at this point in the history
  • Loading branch information
fprochazka committed Oct 3, 2014
1 parent 2e5dc43 commit 69763e7
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions src/Kdyby/Doctrine/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,23 +179,41 @@ public function prepare($statement)


/**
* This method executes very simple query against database
* and if the connection timeouted, it will try to reconnect.
* Ping the server
*
* @throws \Exception
* @return Connection
* When the server is not available the method returns FALSE.
* It is responsibility of the developer to handle this case
* and abort the request or reconnect manually:
*
* @example
*
* if ($conn->ping() === false) {
* $conn->close();
* $conn->connect();
* }
*
* It is undefined if the underlying driver attempts to reconnect
* or disconnect when the connection is not available anymore
* as long it returns TRUE when a reconnect succeeded and
* FALSE when the connection was dropped.
*
* @todo remove me with doctrine/dbal:2.5-stable
* @see https://github.com/doctrine/dbal/blob/7175964c30f4fd54c90f6f9c7c6f7bf49fc1c939/lib/Doctrine/DBAL/Connection.php#L1590
*
* @return bool
*/
public function ping()
{
try {
$this->executeQuery('SELECT 1')->fetchAll();
return TRUE;

} catch (\Exception $e) {
$this->close();
$this->connect();
}
} catch (Doctrine\DBAL\DBALException $e) {
return FALSE;

return $this;
} catch (DBALException $e) {
return FALSE;
}
}


Expand Down

0 comments on commit 69763e7

Please sign in to comment.