Skip to content

Commit

Permalink
https://github.com/opencart/opencart/issues/8976
Browse files Browse the repository at this point in the history
  • Loading branch information
danielkerr committed Dec 24, 2020
1 parent 48ccb99 commit ee125bb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
10 changes: 0 additions & 10 deletions upload/system/library/db.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,4 @@ public function isConnected() {
public function close() {
return $this->adaptor->close();
}

/**
* __destruct
*
* Closes the DB connection when this object is destroyed.
*
*/
public function __destruct() {
$this->adaptor->close();
}
}
11 changes: 11 additions & 0 deletions upload/system/library/db/mysqli.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public function __construct($hostname, $username, $password, $database, $port =
$this->connection = $connection;
$this->connection->report_mode = MYSQLI_REPORT_ERROR;
$this->connection->set_charset('utf8');
$this->connection->query("SET SESSION sql_mode = 'NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION'");
} else {
throw new \Exception('Error: Could not make a database link using ' . $username . '@' . $hostname . '!');
}
Expand Down Expand Up @@ -65,4 +66,14 @@ public function close() {
$this->connection = '';
}
}

/**
* __destruct
*
* Closes the DB connection when this object is destroyed.
*
*/
public function __destruct() {
$this->close();
}
}

2 comments on commit ee125bb

@cgcmart
Copy link

@cgcmart cgcmart commented on ee125bb Dec 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix added public function __destruct() { to upload/system/library/db/mysqli.php under which inserted $this->close(); line 77
will cause php warnings, uncaught errors:

PHP Warning: mysqli::query(): Couldn't fetch mysqli in /system/library/db/mysqli.php on line 20
PHP Warning: DB\MySQLi::query(): Couldn't fetch mysqli in /system/library/db/mysqli.php on line 22
PHP Warning: mysqli::real_escape_string(): Couldn't fetch mysqli in /system/library/db/mysqli.php on line 47

because __destruct is event, after which there will be a need for execution of queries

Also refers to issues #8174, #8684, etc.

@BuslikDrev
Copy link
Contributor

@BuslikDrev BuslikDrev commented on ee125bb Mar 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.