Skip to content

Commit 9a7b876

Browse files
authored
Fixed bug that pgsql cannot init when using pgsql-swoole. (#5730)
1 parent 814976e commit 9a7b876

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/PostgreSqlSwooleExtConnection.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ class PostgreSqlSwooleExtConnection extends Connection
2828
{
2929
use PostgreSqlSwooleExtManagesTransactions;
3030

31-
/**
32-
* @var PostgreSQL
33-
*/
34-
protected mixed $pdo;
35-
3631
protected int $fetchMode = SW_PGSQL_ASSOC;
3732

3833
/**
@@ -110,8 +105,8 @@ public function select(string $query, array $bindings = [], bool $useReadPdo = t
110105

111106
$result = $statement->execute($this->prepareBindings($bindings));
112107

113-
if ($result === false || ! empty($this->pdo->error)) {
114-
throw new QueryException($query, [], new Exception($this->pdo->error));
108+
if ($result === false || ! empty($statement->error)) {
109+
throw new QueryException($query, [], new Exception($statement->error));
115110
}
116111

117112
return $statement->fetchAll($this->fetchMode) ?: [];
@@ -153,7 +148,7 @@ public function queryAll(string $query, array $bindings = []): array
153148

154149
$result = $statement->execute($bindings);
155150
if (! $result) {
156-
throw new QueryException($query, [], new Exception($this->pdo->error));
151+
throw new QueryException($query, [], new Exception($statement->error));
157152
}
158153

159154
return $statement->fetchAll(SW_PGSQL_ASSOC);
@@ -227,9 +222,11 @@ protected function prepare(string $query, bool $useReadPdo = true): PostgreSQLSt
227222
$query = $this->str_replace_once('?', '$' . $num++, $query);
228223
}
229224

230-
$statement = $this->getPdoForSelect($useReadPdo)->prepare($query);
225+
/** @var PostgreSQL $pdo */
226+
$pdo = $this->getPdoForSelect($useReadPdo);
227+
$statement = $pdo->prepare($query);
231228
if (! $statement) {
232-
throw new QueryException($query, [], new Exception($this->pdo->error));
229+
throw new QueryException($query, [], new Exception($pdo->error));
233230
}
234231

235232
return $statement;

0 commit comments

Comments
 (0)