N°5066 - Clean CMDBSource methods (#229)

* Improve function calls

* Deprecate CMDBSource::GetServerInfo

* Improve documentation

* Update core/cmdbsource.class.inc.php

Co-authored-by: Pierre Goiffon <pierre.goiffon@combodo.com>

* Single quotes

* Apply suggestion, so  method still returns empty string instead of null

Co-authored-by: Pierre Goiffon <pierre.goiffon@combodo.com>
This commit is contained in:
Thomas Casteleyn
2022-04-12 17:10:41 +02:00
committed by GitHub
parent 645e612e8b
commit e4a04de9f4

View File

@@ -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