diff --git a/src/Dibi/Drivers/PdoDriver.php b/src/Dibi/Drivers/PdoDriver.php index 6dd9fdc5..4bb5c1e4 100644 --- a/src/Dibi/Drivers/PdoDriver.php +++ b/src/Dibi/Drivers/PdoDriver.php @@ -56,9 +56,15 @@ class PdoDriver implements Dibi\Driver if ($config['resource'] instanceof PDO) { $this->connection = $config['resource']; unset($config['resource'], $config['pdo']); + + if ($this->connection->getAttribute(PDO::ATTR_ERRMODE) !== PDO::ERRMODE_SILENT) { + throw new Dibi\DriverException('PDO connection in exception or warning error mode is not supported.'); + } + } else { try { $this->connection = new PDO($config['dsn'], $config['username'], $config['password'], $config['options']); + $this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT); } catch (\PDOException $e) { if ($e->getMessage() === 'could not find driver') { throw new Dibi\NotSupportedException('PHP extension for PDO is not loaded.'); @@ -67,10 +73,6 @@ class PdoDriver implements Dibi\Driver } } - if ($this->connection->getAttribute(PDO::ATTR_ERRMODE) !== PDO::ERRMODE_SILENT) { - throw new Dibi\DriverException('PDO connection in exception or warning error mode is not supported.'); - } - $this->driverName = $this->connection->getAttribute(PDO::ATTR_DRIVER_NAME); $this->serverVersion = (string) ($config['version'] ?? @$this->connection->getAttribute(PDO::ATTR_SERVER_VERSION)); // @ - may be not supported } diff --git a/tests/dibi/PdoDriver.providedConnection.phpt b/tests/dibi/PdoDriver.providedConnection.phpt index f9364ee3..81d999c2 100644 --- a/tests/dibi/PdoDriver.providedConnection.phpt +++ b/tests/dibi/PdoDriver.providedConnection.phpt @@ -32,8 +32,3 @@ Assert::exception(function () { test('PDO error mode: explicitly set silent', function () { buildPdoDriver(PDO::ERRMODE_SILENT); }); - - -test('PDO error mode: implicitly set silent', function () { - buildPdoDriver(null); -});