\PDO::PARAM_INT, "float" => \PDO::PARAM_STR, "datetime" => \PDO::PARAM_STR, "binary" => \PDO::PARAM_LOB, "string" => \PDO::PARAM_STR, "boolean" => \PDO::PARAM_INT, // FIXME: using \PDO::PARAM_BOOL leads to incompatibilities with versions of SQLite bundled prior to PHP 7.3 ]; protected $st; protected $db; protected $query; public function __construct(\PDO $db, string $query, array $bindings = []) { $this->db = $db; $this->query = $query; $this->retypeArray($bindings); } protected function prepare(string $query): bool { try { $this->st = $this->db->prepare($query); return true; } catch (\PDOException $e) { list($excClass, $excMsg, $excData) = $this->exceptionBuild(); throw new $excClass($excMsg, $excData); } } public function __destruct() { unset($this->st, $this->db); } public function runArray(array $values = []): Result { $this->st->closeCursor(); $this->bindValues($values); try { $this->st->execute(); } catch (\PDOException $e) { list($excClass, $excMsg, $excData) = $this->exceptionBuild(true); throw new $excClass($excMsg, $excData); } return new PDOResult($this->db, $this->st); } protected function bindValue($value, string $type, int $position): bool { return $this->st->bindValue($position, $value, is_null($value) ? \PDO::PARAM_NULL : self::BINDINGS[$type]); } }