Skip to content

Commit cf97719

Browse files
authored
Merge pull request #8 from artemeon/fix/#7-dbclose-can-be-called-more-than-once
introduce dedicated property connected to guard dbconnect and dbclose methods
2 parents a9d642d + 8cb600c commit cf97719

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/Driver/MysqliDriver.php

+13-3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
*/
3232
class MysqliDriver extends DriverAbstract
3333
{
34+
private $connected = false;
35+
3436
/** @var mysqli */
3537
private $linkDB; //DB-Link
3638

@@ -51,6 +53,10 @@ class MysqliDriver extends DriverAbstract
5153
*/
5254
public function dbconnect(ConnectionParameters $objParams)
5355
{
56+
if ($this->connected) {
57+
return true;
58+
}
59+
5460
$port = $objParams->getPort();
5561
if (empty($port)) {
5662
$port = 3306;
@@ -79,6 +85,7 @@ public function dbconnect(ConnectionParameters $objParams)
7985
$this->_pQuery("SET character_set_database ='utf8'", array());
8086
$this->_pQuery("SET character_set_server ='utf8'", array());
8187

88+
$this->connected = true;
8289
return true;
8390
}
8491

@@ -87,10 +94,13 @@ public function dbconnect(ConnectionParameters $objParams)
8794
*/
8895
public function dbclose()
8996
{
90-
if ($this->linkDB !== null) {
91-
$this->linkDB->close();
92-
$this->linkDB = null;
97+
if (!$this->connected) {
98+
return;
9399
}
100+
101+
$this->linkDB->close();
102+
$this->linkDB = null;
103+
$this->connected = false;
94104
}
95105

96106
/**

0 commit comments

Comments
 (0)