1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-06 22:26:43 +02:00

PdoDriver: changes error mode do ERRMODE_SILENT (for PHP 8.0)

This commit is contained in:
David Grudl
2020-10-15 16:39:30 +02:00
parent fa6a1203a9
commit 177a800bff
2 changed files with 6 additions and 9 deletions

View File

@@ -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
}

View File

@@ -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);
});