WIP command center

This commit is contained in:
Daniel Barbero Martin 2021-04-06 17:22:34 +02:00
parent 74afdf9510
commit 0e30f1bc4f

View File

@ -65,14 +65,41 @@ function get_dbconnection(array $setup)
} }
function db_connect($host=null, $db=null, $user=null, $pass=null, $port=null, $critical=true, $charset=null) /**
{ * Connect bbdd.
*
* @param string $host Host.
* @param string $db Db.
* @param string $user User.
* @param string $pass Pass.
* @param string $port Port.
* @param boolean $critical Critical.
* @param string $charset Charset.
*
* @return mysqli|false
*/
function db_connect(
$host=null,
$db=null,
$user=null,
$pass=null,
$port=null,
$critical=true,
$charset=null
) {
global $config; global $config;
static $error = 0; static $error = 0;
switch ($config['dbtype']) { switch ($config['dbtype']) {
case 'mysql': case 'mysql':
$return = mysql_connect_db($host, $db, $user, $pass, $port, $charset); $return = mysql_connect_db(
$host,
$db,
$user,
$pass,
$port,
$charset
);
break; break;
case 'postgresql': case 'postgresql':
@ -85,9 +112,10 @@ function db_connect($host=null, $db=null, $user=null, $pass=null, $port=null, $c
default: default:
$return = false; $return = false;
break;
} }
// Something went wrong // Something went wrong.
if ($return === false) { if ($return === false) {
if ($critical) { if ($critical) {
$url = explode('/', $_SERVER['REQUEST_URI']); $url = explode('/', $_SERVER['REQUEST_URI']);
@ -110,9 +138,12 @@ function db_connect($host=null, $db=null, $user=null, $pass=null, $port=null, $c
include $config['homedir'].'../general/error_screen.php'; include $config['homedir'].'../general/error_screen.php';
exit; exit;
} else if ($error == 0) { } else if ($error == 0) {
// Display the error once even if multiple connection attempts are made // Display the error once even if multiple
// connection attempts are made.
$error = 1; $error = 1;
ui_print_error_message(__('Error connecting to database %s at %s.', $db, $host)); ui_print_error_message(
__('Error connecting to database %s at %s.', $db, $host)
);
} }
} }