MINOR Removed return of connection and changed variables to conincide with r98795 (from r98800)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@102804 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2010-04-14 03:44:38 +00:00
parent c1dc70b88d
commit e89e377cb6

View File

@ -23,42 +23,39 @@ class MySQLDatabaseConfigurationHelper implements DatabaseConfigurationHelper {
/** /**
* Ensure that the database server exists. * Ensure that the database server exists.
* @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
* @return array Result - e.g. array('okay' => true, 'error' => 'details of error') * @return array Result - e.g. array('success' => true, 'error' => 'details of error')
*/ */
public function requireDatabaseServer($databaseConfig) { public function requireDatabaseServer($databaseConfig) {
$okay = false; $success = false;
$conn = @mysql_connect($databaseConfig['server'], null, null); $conn = @mysql_connect($databaseConfig['server'], null, null);
if($conn || mysql_errno() < 2000) { if($conn || mysql_errno() < 2000) {
$okay = true; $success = true;
} else { } else {
$okay = false; $success = false;
$error = mysql_error(); $error = mysql_error();
} }
return array( return array(
'okay' => $okay, 'success' => $success,
'error' => $error 'error' => $error
); );
} }
/** /**
* Ensure a database connection is possible using credentials provided. * Ensure a database connection is possible using credentials provided.
* The established connection resource is returned with the results as well.
*
* @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
* @return array Result - e.g. array('okay' => true, 'connection' => mysql link, 'error' => 'details of error') * @return array Result - e.g. array('success' => true, 'error' => 'details of error')
*/ */
public function requireDatabaseConnection($databaseConfig) { public function requireDatabaseConnection($databaseConfig) {
$okay = false; $success = false;
$conn = @mysql_connect($databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password']); $conn = @mysql_connect($databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password']);
if($conn) { if($conn) {
$okay = true; $success = true;
} else { } else {
$okay = false; $success = false;
$error = mysql_error(); $error = mysql_error();
} }
return array( return array(
'okay' => $okay, 'success' => $success,
'connection' => $conn,
'error' => $error 'error' => $error
); );
} }
@ -68,25 +65,25 @@ class MySQLDatabaseConfigurationHelper implements DatabaseConfigurationHelper {
* or be able to create one if it doesn't exist. * or be able to create one if it doesn't exist.
* *
* @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
* @return array Result - e.g. array('okay' => true, 'existsAlready' => 'true') * @return array Result - e.g. array('success' => true, 'alreadyExists' => 'true')
*/ */
public function requireDatabaseOrCreatePermissions($databaseConfig) { public function requireDatabaseOrCreatePermissions($databaseConfig) {
$okay = false; $success = false;
$existsAlready = false; $alreadyExists = false;
$conn = @mysql_connect($databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password']); $conn = @mysql_connect($databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password']);
if(@mysql_select_db($databaseConfig['database'], $conn)) { if(@mysql_select_db($databaseConfig['database'], $conn)) {
$okay = true; $success = true;
$existsAlready = true; $alreadyExists = true;
} else { } else {
if(@mysql_query("CREATE DATABASE testing123", $conn)) { if(@mysql_query("CREATE DATABASE testing123", $conn)) {
mysql_query("DROP DATABASE testing123", $conn); mysql_query("DROP DATABASE testing123", $conn);
$okay = true; $success = true;
$existsAlready = false; $alreadyExists = false;
} }
} }
return array( return array(
'okay' => $okay, 'success' => $success,
'existsAlready' => $existsAlready 'alreadyExists' => $alreadyExists
); );
} }