diff --git a/pandora_console/include/lib/Core/Config.php b/pandora_console/include/lib/Core/Config.php index 8970d03835..3030491202 100644 --- a/pandora_console/include/lib/Core/Config.php +++ b/pandora_console/include/lib/Core/Config.php @@ -64,39 +64,55 @@ final class Config || $config['history_db_connection'] === false ) { ob_start(); - $config['history_db_connection'] = db_connect( - $config['history_db_host'], - $config['history_db_name'], + + $link = mysqli_init(); + $link->options(MYSQLI_OPT_CONNECT_TIMEOUT, 2); + $rc = mysqli_real_connect( + $link, + $$config['history_db_host'], $config['history_db_user'], io_output_password($config['history_db_pass']), - $config['history_db_port'], - false + $config['history_db_name'], + $config['history_db_port'] ); + if ($rc === false) { + $config['history_db_connection'] = false; + } else { + $config['history_db_connection'] = db_connect( + $config['history_db_host'], + $config['history_db_name'], + $config['history_db_user'], + io_output_password($config['history_db_pass']), + $config['history_db_port'], + false + ); + } + ob_get_clean(); - } - if ($config['history_db_connection'] !== false) { - $data = \db_get_all_rows_sql( - 'SELECT * FROM `tconfig`', - false, - false, - $config['history_db_connection'] + if ($config['history_db_connection'] !== false) { + $data = \db_get_all_rows_sql( + 'SELECT * FROM `tconfig`', + false, + false, + $config['history_db_connection'] + ); + } + + if (is_array($data) !== true) { + return []; + } + + self::$settings = array_reduce( + $data, + function ($carry, $item) { + $carry[$item['token']] = $item['value']; + return $carry; + }, + [] ); } - - if (is_array($data) !== true) { - return []; - } - - self::$settings = array_reduce( - $data, - function ($carry, $item) { - $carry[$item['token']] = $item['value']; - return $carry; - }, - [] - ); } diff --git a/pandora_console/include/lib/Core/DBMaintainer.php b/pandora_console/include/lib/Core/DBMaintainer.php index aa09c385f8..88841c5990 100644 --- a/pandora_console/include/lib/Core/DBMaintainer.php +++ b/pandora_console/include/lib/Core/DBMaintainer.php @@ -156,7 +156,10 @@ final class DBMaintainer return true; } - $dbc = new \mysqli( + $link = mysqli_init(); + $link->options(MYSQLI_OPT_CONNECT_TIMEOUT, 2); + $rc = mysqli_real_connect( + $link, $this->host, $this->user, $this->pass, @@ -164,25 +167,39 @@ final class DBMaintainer $this->port ); - if ((bool) $dbc->connect_error === true) { + if ($rc === false) { $this->dbh = null; $this->connected = false; - $this->lastError = $dbc->connect_errno.': '.$dbc->connect_error; + $this->lastError = __('Connection problems'); } else { - $this->dbh = $dbc; - if (empty($this->charset) === false) { - $dbc->set_charset($this->charset); - } + $dbc = new \mysqli( + $this->host, + $this->user, + $this->pass, + null, + $this->port + ); - if ($this->dbh->select_db($this->name) === false) { - $this->lastError = $this->dbh->errno.': '.$this->dbh->error; - $this->ready = false; + if ((bool) $dbc->connect_error === true) { + $this->dbh = null; + $this->connected = false; + $this->lastError = $dbc->connect_errno.': '.$dbc->connect_error; } else { - $this->lastError = null; - $this->ready = true; - } + $this->dbh = $dbc; + if (empty($this->charset) === false) { + $dbc->set_charset($this->charset); + } - $this->connected = true; + if ($this->dbh->select_db($this->name) === false) { + $this->lastError = $this->dbh->errno.': '.$this->dbh->error; + $this->ready = false; + } else { + $this->lastError = null; + $this->ready = true; + } + + $this->connected = true; + } } }