@@ -97,6 +97,8 @@ public function _pQuery(string $query, array $params): bool
9797 throw new QueryException ('Could not prepare statement: ' . $ this ->getError (), $ query , $ params );
9898 }
9999
100+ $ this ->assertConnected ();
101+
100102 $ result = pg_execute ($ this ->linkDB , $ name , $ params );
101103 if ($ result === false ) {
102104 throw new QueryException ('Could not execute statement: ' . $ this ->getError (), $ query , $ params );
@@ -119,6 +121,8 @@ public function getPArray(string $query, array $params): Generator
119121 throw new QueryException ('Could not prepare statement: ' . $ this ->getError (), $ query , $ params );
120122 }
121123
124+ $ this ->assertConnected ();
125+
122126 $ resultSet = pg_execute ($ this ->linkDB , $ name , $ params );
123127
124128 if ($ resultSet === false ) {
@@ -193,6 +197,8 @@ public function insertOrUpdate(string $table, array $columns, array $values, arr
193197 #[Override]
194198 public function getError (): string
195199 {
200+ $ this ->assertConnected ();
201+
196202 return pg_last_error ($ this ->linkDB );
197203 }
198204
@@ -486,6 +492,8 @@ public function transactionRollback(): void
486492 #[Override]
487493 public function getDbInfo (): array
488494 {
495+ $ this ->assertConnected ();
496+
489497 return pg_version ($ this ->linkDB );
490498 }
491499
@@ -626,6 +634,8 @@ private function getPreparedStatementName(string $query): false | string
626634 return $ sum ;
627635 }
628636
637+ $ this ->assertConnected ();
638+
629639 if (pg_prepare ($ this ->linkDB , $ sum , $ query )) {
630640 $ this ->statementsCache [] = $ sum ;
631641 } else {
@@ -690,4 +700,14 @@ public function getNthLastElementFromSlug(string $column, int $position): string
690700 {
691701 return "SPLIT_PART(REVERSE(SPLIT_PART(REVERSE( $ column), '/', $ position)), '/', 1) " ;
692702 }
703+
704+ /**
705+ * @phpstan-assert Connection $this->linkDB
706+ */
707+ private function assertConnected (): void
708+ {
709+ if (!$ this ->linkDB instanceof Connection) {
710+ throw new ConnectionException ('Database not connected. ' );
711+ }
712+ }
693713}
0 commit comments