ENHANCEMENT Added MySQLDatabaseConfigurationHelper::requireDatabaseVersion() to check whether the connected instance is using version 5.0+ (from r104706)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112375 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2010-10-15 01:10:10 +00:00
parent 537f18195d
commit 8ea659be69

View File

@ -42,6 +42,28 @@ class MySQLDatabaseConfigurationHelper implements DatabaseConfigurationHelper {
); );
} }
/**
* Ensure that the MySQL server version is at least 5.0.
* @param array $databaseConfig Associative array of db configuration, e.g. "server", "username" etc
* @return array Result - e.g. array('success' => true, 'error' => 'details of error')
*/
public function requireDatabaseVersion($databaseConfig) {
$conn = @mysql_connect($databaseConfig['server'], null, null);
$version = @mysql_get_server_info($conn);
$success = false;
$error = '';
if($version) {
$success = version_compare($version, '5.0', '>=');
if(!$success) {
$error = "Your MySQL server version is $version. It's recommended you use at least MySQL 5.0.";
}
}
return array(
'success' => $success,
'error' => $error
);
}
/** /**
* Ensure a database connection is possible using credentials provided. * Ensure a database connection is possible using credentials provided.
* @param array $databaseConfig Associative array of db configuration, e.g. "server", "username" etc * @param array $databaseConfig Associative array of db configuration, e.g. "server", "username" etc