/** * Helper function check the connection to the database, verify a few conditions (minimum version, etc...) and (if connected) * enumerate the existing databases (if possible) * @return mixed false if the connection failed or array('checks' => Array of CheckResult, 'databases' => Array of database names (as strings) or null if not allowed) */ static function CheckServerConnection($sDBServer, $sDBUser, $sDBPwd) { $aResult = array('checks' => array(), 'databases' => null); try { $oDBSource = new CMDBSource(); $oDBSource->Init($sDBServer, $sDBUser, $sDBPwd); $aResult['checks'][] = new CheckResult(CheckResult::INFO, "Connection to '{$sDBServer}' as '{$sDBUser}' successful."); $aResult['checks'][] = new CheckResult(CheckResult::INFO, "Info - User privileges: " . $oDBSource->GetRawPrivileges()); $sDBVersion = $oDBSource->GetDBVersion(); if (version_compare($sDBVersion, self::MYSQL_MIN_VERSION, '>=')) { $aResult['checks'][] = new CheckResult(CheckResult::INFO, "Current MySQL version ({$sDBVersion}), greater than minimum required version (" . self::MYSQL_MIN_VERSION . ")"); // Check some server variables $iMaxAllowedPacket = $oDBSource->GetServerVariable('max_allowed_packet'); $iMaxUploadSize = utils::ConvertToBytes(ini_get('upload_max_filesize')); if ($iMaxAllowedPacket >= 500 + $iMaxUploadSize) { $aResult['checks'][] = new CheckResult(CheckResult::INFO, "MySQL server's max_allowed_packet ({$iMaxAllowedPacket}) is big enough compared to upload_max_filesize ({$iMaxUploadSize})."); } else { if ($iMaxAllowedPacket < $iMaxUploadSize) { $aResult['checks'][] = new CheckResult(CheckResult::WARNING, "MySQL server's max_allowed_packet ({$iMaxAllowedPacket}) is not big enough. Please, consider setting it to at least " . (500 + $iMaxUploadSize) . "."); } } $iMaxConnections = $oDBSource->GetServerVariable('max_connections'); if ($iMaxConnections < 5) { $aResult['checks'][] = new CheckResult(CheckResult::WARNING, "MySQL server's max_connections ({$iMaxConnections}) is not enough. Please, consider setting it to at least 5."); } else { $aResult['checks'][] = new CheckResult(CheckResult::INFO, "MySQL server's max_connections is set to {$iMaxConnections}."); } } else { $aResult['checks'][] = new CheckResult(CheckResult::ERROR, "Error: Current MySQL version is ({$sDBVersion}), minimum required version (" . self::MYSQL_MIN_VERSION . ")"); } try { $aResult['databases'] = $oDBSource->ListDB(); } catch (Exception $e) { $aResult['databases'] = null; } } catch (Exception $e) { return false; } return $aResult; }