From e4a04de9f4a00759b403ebae90d7a871704cffdd Mon Sep 17 00:00:00 2001 From: Thomas Casteleyn Date: Tue, 12 Apr 2022 17:10:41 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B05066=20-=20Clean=20CMDBSource=20methods?= =?UTF-8?q?=20(#229)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Improve function calls * Deprecate CMDBSource::GetServerInfo * Improve documentation * Update core/cmdbsource.class.inc.php Co-authored-by: Pierre Goiffon * Single quotes * Apply suggestion, so method still returns empty string instead of null Co-authored-by: Pierre Goiffon --- core/cmdbsource.class.inc.php | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/core/cmdbsource.class.inc.php b/core/cmdbsource.class.inc.php index 48d67fcf4..be990a208 100644 --- a/core/cmdbsource.class.inc.php +++ b/core/cmdbsource.class.inc.php @@ -351,19 +351,21 @@ class CMDBSource } /** + * Get the version of the database server. + * * @return string * @throws \MySQLException * - * @uses \CMDBSource::QueryToCol() so needs a connection opened ! + * @uses \CMDBSource::QueryToScalar() so needs a connection opened ! */ public static function GetDBVersion() { - $aVersions = self::QueryToCol('SELECT Version() as version', 'version'); - return $aVersions[0]; + return static::QueryToScalar('SELECT VERSION()', 0); } /** - * @return string + * @deprecated Use `CMDBSource::GetDBVersion` instead. + * @uses mysqli_get_server_info */ public static function GetServerInfo() { @@ -1499,20 +1501,14 @@ class CMDBSource * Returns the value of the specified server variable * @param string $sVarName Name of the server variable * @return mixed Current value of the variable - */ + * @throws \MySQLQueryHasNoResultException|\MySQLException + */ public static function GetServerVariable($sVarName) { - $result = ''; - $sSql = "SELECT @@$sVarName as theVar"; - $aRows = self::QueryToArray($sSql); - if (count($aRows) > 0) - { - $result = $aRows[0]['theVar']; - } - return $result; + $sSql = 'SELECT @@'.$sVarName; + return static::QueryToScalar($sSql, 0) ?: ''; } - /** * Returns the privileges of the current user * @return string privileges in a raw format