1111
1212use Dibi ;
1313use Dibi \Helpers ;
14+ use PgSql ;
1415
1516
1617/**
@@ -29,7 +30,7 @@ class PostgreDriver implements Dibi\Driver
2930{
3031 use Dibi \Strict;
3132
32- /** @var resource */
33+ /** @var resource|PgSql\Connection */
3334 private $ connection ;
3435
3536 /** @var int|null Affected rows */
@@ -74,7 +75,7 @@ public function __construct(array $config)
7475 restore_error_handler ();
7576 }
7677
77- if (!is_resource ($ this ->connection )) {
78+ if (!is_resource ($ this ->connection ) && ! $ this -> connection instanceof PgSql \Connection ) {
7879 throw new Dibi \DriverException ($ error ?: 'Connecting error. ' );
7980 }
8081
@@ -120,7 +121,7 @@ public function query(string $sql): ?Dibi\ResultDriver
120121 if ($ res === false ) {
121122 throw static ::createException (pg_last_error ($ this ->connection ), null , $ sql );
122123
123- } elseif (is_resource ($ res )) {
124+ } elseif (is_resource ($ res ) || $ res instanceof PgSql \Result ) {
124125 $ this ->affectedRows = Helpers::false2Null (pg_affected_rows ($ res ));
125126 if (pg_num_fields ($ res )) {
126127 return $ this ->createResultDriver ($ res );
@@ -227,7 +228,9 @@ public function inTransaction(): bool
227228 */
228229 public function getResource ()
229230 {
230- return is_resource ($ this ->connection ) ? $ this ->connection : null ;
231+ return is_resource ($ this ->connection ) || $ this ->connection instanceof PgSql \Connection
232+ ? $ this ->connection
233+ : null ;
231234 }
232235
233236
@@ -258,7 +261,7 @@ public function createResultDriver($resource): PostgreResult
258261 */
259262 public function escapeText (string $ value ): string
260263 {
261- if (!is_resource ( $ this ->connection )) {
264+ if (!$ this ->getResource ( )) {
262265 throw new Dibi \Exception ('Lost connection to server. ' );
263266 }
264267 return "' " . pg_escape_string ($ this ->connection , $ value ) . "' " ;
@@ -267,7 +270,7 @@ public function escapeText(string $value): string
267270
268271 public function escapeBinary (string $ value ): string
269272 {
270- if (!is_resource ( $ this ->connection )) {
273+ if (!$ this ->getResource ( )) {
271274 throw new Dibi \Exception ('Lost connection to server. ' );
272275 }
273276 return "' " . pg_escape_bytea ($ this ->connection , $ value ) . "' " ;
0 commit comments