diff --git a/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php b/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php index 9e293298133..1a33b6609fe 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php @@ -31,7 +31,9 @@ abstract class AbstractPostgreSQLDriver implements Driver, ExceptionConverterDri */ public function convertException($message, DriverException $exception) { - switch ($exception->getSQLState()) { + $sqlState = $exception->getSQLState(); + + switch ($sqlState) { case '40001': case '40P01': return new Exception\DeadlockException($message, $exception); @@ -69,9 +71,13 @@ public function convertException($message, DriverException $exception) case '42P07': return new Exception\TableExistsException($message, $exception); + case '08006': + return new Exception\ConnectionException($message, $exception); + case '7': - // In some case (mainly connection errors) the PDO exception does not provide a SQLSTATE via its code. - // The exception code is always set to 7 here. + // Prior to fixing https://bugs.php.net/bug.php?id=64705 (PHP 7.3.22 and PHP 7.4.10), + // in some cases (mainly connection errors) the PDO exception wouldn't provide a SQLSTATE via its code. + // The exception code would be always set to 7 here. // We have to match against the SQLSTATE in the error message in these cases. if (strpos($exception->getMessage(), 'SQLSTATE[08006]') !== false) { return new Exception\ConnectionException($message, $exception);