Permalink
Browse files

BUGFIX Installer should cache the database connection so queries test…

…ing database creation can be made properly (from r98744)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/phpinstaller/trunk@112095 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information...
1 parent 5663e26 commit 42144c288dd94b7928b8f52a944d3d4bd2c5e1b2 sminnee committed Oct 13, 2010
Showing with 20 additions and 16 deletions.
  1. +20 −16 install.php
View
@@ -194,7 +194,7 @@
*/
class InstallRequirements {
- var $errors, $warnings, $tests;
+ var $errors, $warnings, $tests, $dbConn;
/**
* Just check that the database configuration is okay
@@ -611,11 +611,15 @@ function requireDatabaseFunction($databaseConfig, $testDetails) {
}
}
+ /**
+ * The established database connection is cached to $dbConn on the instance
+ * of this class so various queries can be run via {@link requireDatabaseOrCreatePermissions())
+ */
function requireDatabaseConnection($databaseConfig, $testDetails) {
$this->testing($testDetails);
if($databaseConfig['type'] == 'MySQLDatabase') {
- $conn = @mysql_connect($databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password']);
+ $this->dbConn = $conn = @mysql_connect($databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password']);
if($conn || mysql_errno() < 2000) {
return true;
} else {
@@ -624,13 +628,13 @@ function requireDatabaseConnection($databaseConfig, $testDetails) {
}
} elseif($databaseConfig['type'] == 'MSSQLDatabase') {
if(function_exists('mssql_connect')) {
- $conn = @mssql_connect($databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password'], true);
+ $this->dbConn = $conn = @mssql_connect($databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password'], true);
} else {
$connectionInfo = array(
'UID' => $databaseConfig['username'],
'PWD' => $databaseConfig['password'],
);
- $conn = @sqlsrv_connect($databaseConfig['server'], $connectionInfo);
+ $this->dbConn = $conn = @sqlsrv_connect($databaseConfig['server'], $connectionInfo);
}
if($conn) {
@@ -645,7 +649,7 @@ function requireDatabaseConnection($databaseConfig, $testDetails) {
$userPart = $username ? " user=$username" : '';
$passwordPart = $password ? " password=$password" : '';
$connstring = "host=$server port=5432 {$userPart}{$passwordPart}";
- $conn = @pg_connect($connstring);
+ $this->dbConn = $conn = @pg_connect($connstring);
if($conn) {
return true;
@@ -709,7 +713,7 @@ function requireMySQLVersion($version, $testDetails) {
} else {
list($majorRequested, $minorRequested) = explode('.', $version);
$result = mysql_query('SELECT VERSION()');
- $row=mysql_fetch_row($result);
+ $row = mysql_fetch_row($result);
$version = ereg_replace("([A-Za-z-])", "", $row[0]);
list($majorHas, $minorHas) = explode('.', substr(trim($version), 0, 3));
@@ -728,38 +732,38 @@ function requireDatabaseOrCreatePermissions($databaseConfig, $testDetails) {
if($databaseConfig['type'] == 'MySQLDatabase') {
$conn = @mysql_connect($databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password']);
- if(@mysql_select_db($databaseConfig['database'])) {
+ if(@mysql_select_db($databaseConfig['database'], $this->dbConn)) {
$okay = "Database '$databaseConfig[database]' exists";
} else {
- if(@mysql_query("CREATE DATABASE testing123")) {
- mysql_query("DROP DATABASE testing123");
+ if(@mysql_query("CREATE DATABASE testing123", $this->dbConn)) {
+ mysql_query("DROP DATABASE testing123", $this->dbConn);
$okay = "Able to create a new database";
}
}
} elseif($databaseConfig['type'] == 'MSSQLDatabase') {
if(@mysql_select_db($databaseConfig['database'])) {
$okay = "Database '$databaseConfig[database]' exists";
} else {
- if(function_exists('mssql_connect') && @mssql_query("CREATE DATABASE testing123")) {
- mssql_query("DROP DATABASE testing123");
+ if(function_exists('mssql_connect') && @mssql_query("CREATE DATABASE testing123", $this->dbConn)) {
+ mssql_query($this->dbConn, "DROP DATABASE testing123");
$okay = "Able to create a new database";
- } elseif(function_exists('sqlsrv_connect') && @sqlsrv_query("CREATE DATABASE testing123")) {
- sqlsrv_query("DROP DATABASE testing123");
+ } elseif(function_exists('sqlsrv_connect') && @sqlsrv_query($this->dbConn, "CREATE DATABASE testing123")) {
+ sqlsrv_query($this->dbConn, "DROP DATABASE testing123");
$okay = "Able to create a new database";
}
}
} elseif($databaseConfig['type'] == 'PostgreSQLDatabase') {
$database = $databaseConfig['database'];
$dbExists = false;
- $result = pg_query("SELECT datname FROM pg_database WHERE datname = '$database'");
+ $result = pg_query($this->dbConn, "SELECT datname FROM pg_database WHERE datname = '$database'");
if(pg_fetch_array($result)) $dbExists = true;
if($dbExists) {
$okay = "Database '$database' exists";
} else {
- if(@pg_query("CREATE DATABASE testing123")) {
- pg_query("DROP DATABASE testing123");
+ if(@pg_query($this->dbConn, "CREATE DATABASE testing123")) {
+ pg_query($this->dbConn, "DROP DATABASE testing123");
$okay = "Able to create a new database";
}
}

0 comments on commit 42144c2

Please sign in to comment.