added missing mysqli result close calls

This commit is contained in:
Steffen Schröder 2014-03-20 16:19:09 +01:00
parent 415ca788c2
commit 2b69a7aad5

View File

@ -1,6 +1,7 @@
<?php <?php
namespace ManiaControl; namespace ManiaControl;
use ManiaControl\Callbacks\TimerListener; use ManiaControl\Callbacks\TimerListener;
/** /**
@ -8,7 +9,7 @@ use ManiaControl\Callbacks\TimerListener;
* *
* @author steeffeen & kremsy * @author steeffeen & kremsy
*/ */
class Database implements TimerListener{ class Database implements TimerListener {
/** /**
* Public properties * Public properties
*/ */
@ -40,29 +41,30 @@ class Database implements TimerListener{
$port = (int) $port[0]; $port = (int) $port[0];
$user = (string) $user[0]; $user = (string) $user[0];
$pass = (string) $pass[0]; $pass = (string) $pass[0];
//Enable mysqli Reconnect // Enable mysqli Reconnect
ini_set('mysqli.reconnect', 'on'); ini_set('mysqli.reconnect', 'on');
// Open database connection // Open database connection
$this->mysqli = @new \mysqli($host, $user, $pass, null, $port); $this->mysqli = @new \mysqli($host, $user, $pass, null, $port);
if ($this->mysqli->connect_error) { if ($this->mysqli->connect_error) {
trigger_error($this->mysqli->connect_error, E_USER_ERROR); trigger_error($this->mysqli->connect_error, E_USER_ERROR);
} }
$this->mysqli->set_charset("utf8"); $this->mysqli->set_charset("utf8");
$this->initDatabase(); $this->initDatabase();
$this->optimizeTables(); $this->optimizeTables();
//Register Method which checks the Database Connection every 5 seconds // Register Method which checks the Database Connection every 5 seconds
$this->maniaControl->timerManager->registerTimerListening($this, 'checkConnection', 5000); $this->maniaControl->timerManager->registerTimerListening($this, 'checkConnection', 5000);
} }
/** /**
* Check if Connection still exists every 5 seconds * Check if Connection still exists every 5 seconds
*
* @param $time * @param $time
*/ */
public function checkConnection($time){ public function checkConnection($time) {
if (!$this->mysqli->ping()) { if (!$this->mysqli->ping()) {
$this->maniaControl->quit("The MySQL server has gone away"); $this->maniaControl->quit("The MySQL server has gone away");
} }
@ -72,7 +74,7 @@ class Database implements TimerListener{
* Destruct database connection * Destruct database connection
*/ */
public function __destruct() { public function __destruct() {
if($this->mysqli){ if ($this->mysqli) {
$this->mysqli->close(); $this->mysqli->close();
} }
} }
@ -132,6 +134,7 @@ class Database implements TimerListener{
} }
$count = $result->num_rows; $count = $result->num_rows;
if ($count <= 0) { if ($count <= 0) {
$result->close();
return true; return true;
} }
$optimizeQuery = "OPTIMIZE TABLE "; $optimizeQuery = "OPTIMIZE TABLE ";
@ -144,6 +147,7 @@ class Database implements TimerListener{
} }
$index++; $index++;
} }
$result->close();
$optimizeQuery .= ";"; $optimizeQuery .= ";";
$this->mysqli->query($optimizeQuery); $this->mysqli->query($optimizeQuery);
if ($this->mysqli->error) { if ($this->mysqli->error) {