15
15
use chillerlan \Database \Dialects \{Dialect , Postgres };
16
16
use chillerlan \Database \Result ;
17
17
use Throwable ;
18
+ use PgSql \Connection ;
18
19
19
- use function bin2hex , call_user_func_array , implode , in_array , is_bool , is_resource , pg_close , pg_connect ,
20
+ use function bin2hex , call_user_func_array , implode , in_array , is_bool , pg_close , pg_connect ,
20
21
pg_execute , pg_field_type , pg_free_result , pg_prepare , pg_query , pg_version , preg_replace_callback ;
21
22
22
23
/**
@@ -27,16 +28,16 @@ final class PostgreSQL extends DriverAbstract{
27
28
/**
28
29
* Holds the database resource object
29
30
*
30
- * @var resource|null
31
+ * @var \PgSql\Connection| resource|null
31
32
*/
32
- private $ db = null ;
33
+ private ? Connection $ db = null ;
33
34
34
35
/**
35
36
* @inheritdoc
36
37
*/
37
38
public function connect ():DriverInterface {
38
39
39
- if (is_resource ( $ this ->db ) ){
40
+ if ($ this ->db !== null ){
40
41
return $ this ;
41
42
}
42
43
@@ -69,19 +70,23 @@ public function connect():DriverInterface{
69
70
*/
70
71
public function disconnect ():bool {
71
72
72
- if (is_resource ($ this ->db )){
73
- return pg_close ($ this ->db );
73
+ if ($ this ->db !== null ){
74
+ $ ret = pg_close ($ this ->db );
75
+
76
+ if ($ ret === true ){
77
+ $ this ->db = null ;
78
+ }
79
+
80
+ return $ ret ;
74
81
}
75
82
76
83
return true ;
77
84
}
78
85
79
86
/**
80
87
* @inheritdoc
81
- *
82
- * @return resource|null
83
88
*/
84
- public function getDBResource (){
89
+ public function getDBResource ():? Connection {
85
90
return $ this ->db ;
86
91
}
87
92
@@ -97,7 +102,7 @@ public function getDialect():Dialect{
97
102
*/
98
103
public function getClientInfo ():string {
99
104
100
- if (! is_resource ( $ this ->db ) ){
105
+ if ($ this ->db === null ){
101
106
return 'disconnected, no info available ' ;
102
107
}
103
108
@@ -111,7 +116,7 @@ public function getClientInfo():string{
111
116
*/
112
117
public function getServerInfo ():string {
113
118
114
- if (! is_resource ( $ this ->db ) ){
119
+ if ($ this ->db === null ){
115
120
return 'disconnected, no info available ' ;
116
121
}
117
122
0 commit comments