From 177a800bff53f672dc0a18d48905870bd166899b Mon Sep 17 00:00:00 2001 From: David Grudl Date: Thu, 15 Oct 2020 16:39:30 +0200 Subject: [PATCH] PdoDriver: changes error mode do ERRMODE_SILENT (for PHP 8.0) --- src/Dibi/Drivers/PdoDriver.php | 10 ++++++---- tests/dibi/PdoDriver.providedConnection.phpt | 5 ----- 2 files changed, 6 insertions(+), 9 deletions(-) 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); -});