Merge pull request #12 from stojg/bug-infinite-loop-on-failed-connect

BUG: Infinite loop on failed connect to a postgresql server
This commit is contained in:
Sam Minnée 2013-02-26 14:46:35 -08:00
commit c389d79398
1 changed files with 10 additions and 6 deletions

View File

@ -147,22 +147,26 @@ class PostgreSQLDatabase extends SS_Database {
if(self::$check_database_exists) {
$this->dbConn = pg_connect('host=' . $parameters['server'] . ' port=' . $port . ' dbname=postgres' . $username . $password);
if(!$this->databaseExists($dbName))
if(!$this->dbConn) {
throw new ErrorException("Couldn't connect to PostgreSQL database");
}
if(!$this->databaseExists($dbName)) {
$this->createDatabase($dbName);
}
}
//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);
if(!$this->dbConn) {
throw new ErrorException("Couldn't connect to PostgreSQL database");
}
//By virtue of getting here, the connection is active:
$this->active=true;
$this->database = $dbName;
if(!$this->dbConn) {
$this->databaseError("Couldn't connect to PostgreSQL database");
return false;
}
// Set up the schema if required
$schema = isset($parameters['schema']) ? $parameters['schema'] : $this->currentSchema();
// Edge-case - database with no schemas: