2017-12-19 22:15:05 +00:00
|
|
|
<?php
|
|
|
|
/** @license MIT
|
|
|
|
* Copyright 2017 J. King, Dustin Wilson et al.
|
|
|
|
* See LICENSE and AUTHORS files for details */
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2021-04-14 15:17:01 +00:00
|
|
|
|
2017-12-19 22:15:05 +00:00
|
|
|
namespace JKingWeb\Arsse\Db;
|
|
|
|
|
|
|
|
trait PDODriver {
|
|
|
|
use PDOError;
|
|
|
|
|
2024-12-15 21:31:57 +00:00
|
|
|
protected $db;
|
|
|
|
|
2017-12-19 22:15:05 +00:00
|
|
|
public function exec(string $query): bool {
|
|
|
|
try {
|
|
|
|
$this->db->exec($query);
|
|
|
|
return true;
|
|
|
|
} catch (\PDOException $e) {
|
2020-03-01 20:16:50 +00:00
|
|
|
[$excClass, $excMsg, $excData] = $this->buildPDOException();
|
2017-12-19 22:15:05 +00:00
|
|
|
throw new $excClass($excMsg, $excData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function query(string $query): Result {
|
|
|
|
try {
|
|
|
|
$r = $this->db->query($query);
|
|
|
|
} catch (\PDOException $e) {
|
2020-03-01 20:16:50 +00:00
|
|
|
[$excClass, $excMsg, $excData] = $this->buildPDOException();
|
2017-12-19 22:15:05 +00:00
|
|
|
throw new $excClass($excMsg, $excData);
|
|
|
|
}
|
2018-12-06 22:46:00 +00:00
|
|
|
return new PDOResult($this->db, $r);
|
2017-12-19 22:15:05 +00:00
|
|
|
}
|
2019-03-02 03:36:25 +00:00
|
|
|
|
|
|
|
public function literalString(string $str): string {
|
|
|
|
return $this->db->quote($str);
|
|
|
|
}
|
2017-12-22 16:51:58 +00:00
|
|
|
}
|