From 579ca1aabc2a478cc39573689e1030cb6f609891 Mon Sep 17 00:00:00 2001 From: cytopia Date: Tue, 25 Oct 2016 21:13:23 +0200 Subject: [PATCH] Intranet: Better error handling --- .devilbox/www/htdocs/index.php | 11 +++++++---- .devilbox/www/include/functions.php | 28 ++++++++++++++++++++-------- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/.devilbox/www/htdocs/index.php b/.devilbox/www/htdocs/index.php index c6788f92..b45a9fe8 100644 --- a/.devilbox/www/htdocs/index.php +++ b/.devilbox/www/htdocs/index.php @@ -141,28 +141,28 @@ MySQL socket - + '.$error.'' : $ENV['MYSQL_SOCKET_PATH']; ?> MySQL test - OK localhost:3306' : 'Failoed: localhost:3306'; ?> + OK localhost:3306' : 'Failed: localhost:3306
'.$err.''; ?> MySQL test - OK 127.0.0.1:3306' : 'Failed: 127.0.0.1:3306'; ?> + OK 127.0.0.1:3306' : 'Failed: 127.0.0.1:3306
'.$err.''; ?> MySQL test - OK '.$MYSQL_HOST_ADDR.':3306' : 'Failed: '.$MYSQL_HOST_ADDR.':3306'; ?> + OK '.$MYSQL_HOST_ADDR.':3306' : 'Failed: '.$MYSQL_HOST_ADDR.':3306
'.$err.''; ?> @@ -300,6 +300,9 @@ ./etc + MySQL socket + ./run/mysql/mysqld.sock + Log directory ./log diff --git a/.devilbox/www/include/functions.php b/.devilbox/www/include/functions.php index fe82726a..115e92dc 100644 --- a/.devilbox/www/include/functions.php +++ b/.devilbox/www/include/functions.php @@ -112,6 +112,10 @@ function my_mysqli_close($link) { */ function my_mysqli_select(&$err, $link, $query, $callback = NULL) { + if (!$link) { + return FALSE; + } + if (!($result = mysqli_query($link, $query))) { $err = mysqli_error($link); return FALSE; @@ -166,7 +170,9 @@ function getDatabases() { S.SCHEMA_NAME != 'performance_schema' AND S.SCHEMA_NAME != 'information_schema'"; - return my_mysqli_select($error, $GLOBALS['MY_MYSQL_LINK'], $sql, $callback); + $databases = my_mysqli_select($error, $GLOBALS['MY_MYSQL_LINK'], $sql, $callback); + + return $databases ? $databases : array(); } /** @@ -249,8 +255,9 @@ function getMySQLConfig() { }; $sql = 'SHOW VARIABLES;'; - return my_mysqli_select($error, $GLOBALS['MY_MYSQL_LINK'], $sql, $callback); + $configs = my_mysqli_select($error, $GLOBALS['MY_MYSQL_LINK'], $sql, $callback); + return $configs ? $configs : array(); } @@ -269,10 +276,10 @@ function php_has_valid_mysql_socket(&$error) { return FALSE; } - if (getMySQLConfigByKey('socket') != $ENV['MYSQL_SOCKET_PATH']) { - $error = 'Mounted from mysql:'.$ENV['MYSQL_SOCKET_PATH']. ', but socket is in mysql:'.getMySQLConfigByKey('socket'); - return FALSE; - } + //if (getMySQLConfigByKey('socket') != $ENV['MYSQL_SOCKET_PATH']) { + // $error = 'Mounted from mysql:'.$ENV['MYSQL_SOCKET_PATH']. ', but socket is in mysql:'.getMySQLConfigByKey('socket'); + // return FALSE; + //} $error = ''; return TRUE; @@ -421,9 +428,14 @@ function getHttpVersion() { * Get MySQL Version * @return [type] [description] */ - function getMySQLVersion() { - return getMySQLConfigByKey('version_comment') . ' ' . getMySQLConfigByKey('version'); + $name = getMySQLConfigByKey('version_comment'); + $version = getMySQLConfigByKey('version'); + + if (!$name && !$version) { + return 'Unknown Version'; + } + return $name . ' ' . $version; } function getPHPVersion() {