FIX: Fix fatal bugs in previous commit.

This commit is contained in:
Sam Minnee 2014-02-14 15:27:36 +13:00
parent bc37bf7a4f
commit 863ead3255

View File

@ -142,12 +142,11 @@ class PostgreSQLDatabase extends SS_Database {
$port = empty($parameters['port']) ? 5432 : $parameters['port']; $port = empty($parameters['port']) ? 5432 : $parameters['port'];
// Close old connection
if($this->dbConn) pg_close($this->dbConn);
// First, we need to check that this database exists. To do this, we will connect to the 'postgres' database first // First, we need to check that this database exists. To do this, we will connect to the 'postgres' database first
// some setups prevent access to this database so set PostgreSQLDatabase::$check_database_exists = false // some setups prevent access to this database so set PostgreSQLDatabase::$check_database_exists = false
if(self::$check_database_exists) { if(self::$check_database_exists) {
// Close the old connection
if($this->dbConn) pg_close($this->dbConn);
$this->dbConn = pg_connect('host=' . $parameters['server'] . ' port=' . $port . ' dbname=postgres' . $username . $password); $this->dbConn = pg_connect('host=' . $parameters['server'] . ' port=' . $port . ' dbname=postgres' . $username . $password);
if(!$this->dbConn) { if(!$this->dbConn) {
@ -161,6 +160,9 @@ class PostgreSQLDatabase extends SS_Database {
} }
} }
// Close the old connection
if($this->dbConn) pg_close($this->dbConn);
//Now we can be sure that this database exists, so we can connect to it //Now we can be sure that this database exists, so we can connect to it
$this->dbConn = pg_connect('host=' . $parameters['server'] . ' port=' . $port . ' dbname=' . $dbName . $username . $password); $this->dbConn = pg_connect('host=' . $parameters['server'] . ' port=' . $port . ' dbname=' . $dbName . $username . $password);
@ -337,11 +339,10 @@ class PostgreSQLDatabase extends SS_Database {
$this->database = $dbname; $this->database = $dbname;
$this->tableList = $this->fieldList = $this->indexList = null; $this->tableList = $this->fieldList = $this->indexList = null;
// Close old connection
if($this->dbConn) pg_close($this->dbConn);
// Switch to the database if it exists // Switch to the database if it exists
if($this->databaseExists($dbname)) { if($this->databaseExists($dbname)) {
// Close old connection
if($this->dbConn) pg_close($this->dbConn);
$this->dbConn = pg_connect('host=' . $parameters['server'] . ' port=' . $port . ' dbname=' . $dbname . $username . $password); $this->dbConn = pg_connect('host=' . $parameters['server'] . ' port=' . $port . ' dbname=' . $dbname . $username . $password);
if(!$this->dbConn) { if(!$this->dbConn) {
@ -363,6 +364,8 @@ class PostgreSQLDatabase extends SS_Database {
// Inactive database needs to be created; connect to the 'postgres' database in the meantime // Inactive database needs to be created; connect to the 'postgres' database in the meantime
} else { } else {
// Close old connection
if($this->dbConn) pg_close($this->dbConn);
$this->dbConn = pg_connect('host=' . $parameters['server'] . ' port=' . $port . ' dbname=postgres' . $username . $password); $this->dbConn = pg_connect('host=' . $parameters['server'] . ' port=' . $port . ' dbname=postgres' . $username . $password);
$this->active = false; $this->active = false;
} }
@ -1771,7 +1774,8 @@ class PostgreSQLDatabase extends SS_Database {
* Using PHP's addslashes method won't work in MSSQL * Using PHP's addslashes method won't work in MSSQL
*/ */
function addslashes($value){ function addslashes($value){
return pg_escape_string($this->dbConn, $value); if($this->dbConn) return pg_escape_string($this->dbConn, $value);
else return pg_escape_string($value);
} }
/* /*