|
11 | 11 | /** |
12 | 12 | * @template-implements \Iterator<int, array> |
13 | 13 | */ |
14 | | -class DriverPDO implements \Iterator |
| 14 | +class DriverPDO implements \Iterator, DriverPDOInterface |
15 | 15 | { |
16 | | - private \PDO $DBH; |
| 16 | + protected \PDO $DBH; |
17 | 17 | private string $DSN; |
18 | 18 | /** @psalm-suppress PropertyNotSetInConstructor */ |
19 | 19 | private \PDOStatement $STH; |
@@ -63,6 +63,26 @@ private function preConnectionExec(): void |
63 | 63 | public function __destruct() |
64 | 64 | { |
65 | 65 | } |
| 66 | + public function getDBH(): \PDO |
| 67 | + { |
| 68 | + return $this->DBH; |
| 69 | + } |
| 70 | + public function beginTransaction(): bool |
| 71 | + { |
| 72 | + return $this->DBH->beginTransaction(); |
| 73 | + } |
| 74 | + public function inTransaction(): bool |
| 75 | + { |
| 76 | + return $this->DBH->inTransaction(); |
| 77 | + } |
| 78 | + public function commit(): bool |
| 79 | + { |
| 80 | + return $this->DBH->commit(); |
| 81 | + } |
| 82 | + public function rollback(): bool |
| 83 | + { |
| 84 | + return $this->DBH->rollBack(); |
| 85 | + } |
66 | 86 | private function table(string $table): string |
67 | 87 | { |
68 | 88 | return $this->table_prefix . $table . ' '; |
@@ -144,25 +164,14 @@ public function query(string $sql, string $param_type = "", mixed ...$params): s |
144 | 164 | } |
145 | 165 | try { |
146 | 166 | $this->insert_id = $this->DBH->lastInsertId(); |
147 | | - } catch (\PDOException $ignored) { |
| 167 | + } catch (\PDOException) { |
148 | 168 | // Ошибка только с postgresql, предположительно, необходимо вызывать NEXTVAL('?') до LASTVAL() |
149 | 169 | //Fatal error: Uncaught PDOException: SQLSTATE[55000]: Object not in prerequisite state: 7 ERROR: |
150 | 170 | //lastval is not yet defined in this session in Utils/DBDriverPDO.php:136 |
151 | 171 | } |
152 | 172 | return $this; |
153 | 173 | } |
154 | 174 |
|
155 | | - // public function execute(){ |
156 | | - // try { |
157 | | - // $this->STH->execute(); |
158 | | - // } catch (\PDOException $e) { |
159 | | - // $this->debug->debug_error($param_type ? |
160 | | - // "[{$this->database}] Statement execution error: {$e}\n$sql with params:\n$param_type -> " . implode(', ', $params) : |
161 | | - // "[{$this->database}] Statement execution error: {$e}\n$sql"); |
162 | | - // throw new DBException('SQL query error'); |
163 | | - // } |
164 | | - // } |
165 | | - |
166 | 175 | public function getStatementHandler(): \PDOStatement |
167 | 176 | { |
168 | 177 | return $this->STH; |
@@ -238,20 +247,10 @@ public function all(): array |
238 | 247 | * @param array $constructor_args Аргументы для конструктора передаваемого класса, для заполнения |
239 | 248 | * @return T|null Возвращает объект с параметрами класса как в БД и заполненными добавочными данными из аргументов констркутора класса |
240 | 249 | */ |
241 | | - public function obj($class = \stdClass::class, array $constructor_args = []) |
| 250 | + public function obj($class = \stdClass::class, array $constructor_args = []): object|null |
242 | 251 | { |
243 | 252 | return $this->STH->fetchObject($class, $constructor_args) ?: null; |
244 | 253 | } |
245 | | - /** |
246 | | - * Индексированный массив объектов результата |
247 | | - * Use objects() |
248 | | - * @deprecated |
249 | | - * @return array |
250 | | - */ |
251 | | - public function object(): array |
252 | | - { |
253 | | - return $this->objects(); |
254 | | - } |
255 | 254 | // Индексированный массив объектов результата |
256 | 255 | /** |
257 | 256 | * @template T of object |
|
0 commit comments