Skip to content

Commit b1210f0

Browse files
committed
fix mysqli connection errors and db::getDatabaseSize()
1 parent 70e865b commit b1210f0

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

server/lib/classes/db_mysql.inc.php

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,15 @@ public function __construct($host = NULL , $user = NULL, $pass = NULL, $database
7878
$this->_iConnId = mysqli_init();
7979

8080
mysqli_real_connect($this->_iConnId, $this->dbHost, $this->dbUser, $this->dbPass, '', (int)$this->dbPort, NULL, $this->dbClientFlags);
81-
for($try=0;(!is_object($this->_iConnId) || mysqli_connect_error()) && $try < 5;++$try) {
81+
for($try=0;(!is_object($this->_iConnId) || mysqli_connect_errno()) && $try < 5;++$try) {
8282
sleep($try);
83+
if(!is_object($this->_iConnId)) {
84+
$this->_iConnId = mysqli_init();
85+
}
8386
mysqli_real_connect($this->_iConnId, $this->dbHost, $this->dbUser, $this->dbPass, '', (int)$this->dbPort, NULL, $this->dbClientFlags);
8487
}
8588

86-
if(!is_object($this->_iConnId) || mysqli_connect_error()) {
89+
if(!is_object($this->_iConnId) || mysqli_connect_errno()) {
8790
$this->_iConnId = null;
8891
$this->_sqlerror('Zugriff auf Datenbankserver fehlgeschlagen! / Database server not accessible!', '', true);
8992
return false;
@@ -193,7 +196,7 @@ private function _query($sQuery = '') {
193196
$try = 0;
194197
do {
195198
$try++;
196-
$ok = mysqli_ping($this->_iConnId);
199+
$ok = (is_object($this->_iConnId)) ? mysqli_ping($this->_iConnId) : false;
197200
if(!$ok) {
198201
if(!mysqli_real_connect(mysqli_init(), $this->dbHost, $this->dbUser, $this->dbPass, $this->dbName, (int)$this->dbPort, NULL, $this->dbClientFlags)) {
199202
if($this->errorNumber == '111') {
@@ -550,28 +553,18 @@ public function diffrec($record_old, $record_new) {
550553
* @param string $database_name
551554
* @return int - database-size in bytes
552555
*/
553-
554-
555556
public function getDatabaseSize($database_name) {
556557
global $app;
557558

558-
include 'lib/mysql_clientdb.conf';
559-
560-
/* Connect to the database */
561-
$link = mysqli_connect($clientdb_host, $clientdb_user, $clientdb_password);
562-
if (!$link) {
563-
$app->log('Unable to connect to the database'.mysqli_connect_error(), LOGLEVEL_DEBUG);
564-
return;
565-
}
559+
require_once 'lib/mysql_clientdb.conf';
566560

567-
/* Get database-size from information_schema */
568-
$result = mysqli_query($link, "SELECT SUM(data_length+index_length) FROM information_schema.TABLES WHERE table_schema='".mysqli_real_escape_string($link, $database_name)."'");
561+
$result = $this->_query("SELECT SUM(data_length+index_length) FROM information_schema.TABLES WHERE table_schema='".$this->escape($database_name)."'");
569562
if(!$result) {
570-
$app->log('Unable to get the database-size for ' . $database_name . ': '.mysqli_error($link), LOGLEVEL_DEBUG);
563+
$this->_sqlerror('Unable to get the database-size for ' . $database_name);
571564
return;
572565
}
573-
$database_size = mysqli_fetch_row($result);
574-
mysqli_close($link);
566+
$database_size = $result->getAsRow();
567+
$result->free();
575568
return $database_size[0];
576569
}
577570

0 commit comments

Comments
 (0)