- new API to get the MySQL version

- safer way to check if a DB exists (not fully tested yet)

SVN:code[6]
This commit is contained in:
Denis Flaven
2009-03-27 10:31:14 +00:00
parent 00f1734747
commit 6d3c13a781
2 changed files with 27 additions and 6 deletions

View File

@@ -39,7 +39,7 @@ class CMDBSource
self::$m_sDBUser = $sUser;
self::$m_sDBPwd = $sPwd;
self::$m_sDBName = $sSource;
if (!self::$m_resDBLink = mysql_pconnect($sServer, $sUser, $sPwd))
if (!self::$m_resDBLink = @mysql_pconnect($sServer, $sUser, $sPwd))
{
throw new MySQLException('Could not connect to the DB server', array('host'=>$sServer, 'user'=>$sUser));
}
@@ -52,15 +52,37 @@ class CMDBSource
}
}
public static function IsDB($sSource)
public static function ListDB()
{
$aDBs = self::QueryToCol('SHOW DATABASES', 'Database');
// Show Database does return the DB names in lower case
$sSourceRef = strtolower($sSource);
return (in_array($sSourceRef, $aDBs));
return $aDBs;
}
public static function IsDB($sSource)
{
try
{
$aDBs = self::ListDB();
// Show Database does return the DB names in lower case
$sSourceRef = strtolower($sSource);
return (in_array($sSourceRef, $aDBs));
}
catch(Exception $e)
{
// In case we don't have rights to enumerate the databases
// Let's try to connect directly
return @mysql_select_db($sSource, self::$m_resDBLink);
}
}
public static function GetDBVersion()
{
$aVersions = self::QueryToCol('SELECT Version() as version', 'version');
return $aVersions[0];
}
public static function SelectDB($sSource)
{
if (!mysql_select_db($sSource, self::$m_resDBLink))

View File

@@ -1843,7 +1843,6 @@ abstract class MetaModel
public static function DBExists()
{
return true; // Not enough rights to query for other DB
// returns true if at least one table exists (taking into account the DB sharing)
// then some tables might be missing, but that is made in DBCheckFormat
//