Arsse/lib/Db/PDODriver.php
J. King c4a41255b0 Experimental native MySQL driver
No testing has been performed yet, but changes are extensive enough to
warrant a commit. Of particular note:

- SQL states are enumerated in a separate trait to reduce duplication
- PDOStatement is now an abstract class to avoid duplication of
engine-specific error handling
- Error handling has been cleaned up somewhat
2019-01-10 19:01:32 -05:00

31 lines
856 B
PHP

<?php
/** @license MIT
* Copyright 2017 J. King, Dustin Wilson et al.
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Arsse\Db;
trait PDODriver {
use PDOError;
public function exec(string $query): bool {
try {
$this->db->exec($query);
return true;
} catch (\PDOException $e) {
list($excClass, $excMsg, $excData) = $this->buildPDOException();
throw new $excClass($excMsg, $excData);
}
}
public function query(string $query): Result {
try {
$r = $this->db->query($query);
} catch (\PDOException $e) {
list($excClass, $excMsg, $excData) = $this->buildPDOException();
throw new $excClass($excMsg, $excData);
}
return new PDOResult($this->db, $r);
}
}