Skip to content

Commit

Permalink
Merge bc517ac into d24fc4d
Browse files Browse the repository at this point in the history
  • Loading branch information
dakujem committed Jun 22, 2021
2 parents d24fc4d + bc517ac commit f2b17ff
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
20 changes: 12 additions & 8 deletions src/Dibi/Drivers/PdoDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Dibi;
use Dibi\Helpers;
use PDO;
use PDOException;


/**
Expand Down Expand Up @@ -57,8 +58,8 @@ public function __construct(array $config)
$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.');
if ($this->connection->getAttribute(PDO::ATTR_ERRMODE) === PDO::ERRMODE_WARNING) {
throw new Dibi\DriverException('PDO connection in warning error mode is not supported.');
}

} else {
Expand Down Expand Up @@ -93,15 +94,18 @@ public function disconnect(): void
*/
public function query(string $sql): ?Dibi\ResultDriver
{
$res = $this->connection->query($sql);
if ($res) {
$this->affectedRows = $res->rowCount();
return $res->columnCount() ? $this->createResultDriver($res) : null;
try {
$res = $this->connection->query($sql);
if ($res) {
$this->affectedRows = $res->rowCount();
return $res->columnCount() ? $this->createResultDriver($res) : null;
}
[$sqlState, $code, $message] = $this->connection->errorInfo();
} catch (PDOException $e) {
[$sqlState, $code, $message] = $e->errorInfo;
}

$this->affectedRows = null;

[$sqlState, $code, $message] = $this->connection->errorInfo();
$message = "SQLSTATE[$sqlState]: $message";
switch ($this->driverName) {
case 'mysql':
Expand Down
8 changes: 3 additions & 5 deletions tests/dibi/PdoDriver.providedConnection.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@ function buildPdoDriver(?int $errorMode)
}


// PDO error mode: exception
Assert::exception(function () {
buildPdoDriver(PDO::ERRMODE_EXCEPTION);
}, Dibi\DriverException::class, 'PDO connection in exception or warning error mode is not supported.');
// PDO error mode: exception is accepted
buildPdoDriver(PDO::ERRMODE_EXCEPTION);


// PDO error mode: warning
Assert::exception(function () {
buildPdoDriver(PDO::ERRMODE_WARNING);
}, Dibi\DriverException::class, 'PDO connection in exception or warning error mode is not supported.');
}, Dibi\DriverException::class, 'PDO connection in warning error mode is not supported.');


test('PDO error mode: explicitly set silent', function () {
Expand Down

0 comments on commit f2b17ff

Please sign in to comment.