mirror of
https://github.com/silverstripe/silverstripe-postgresql
synced 2024-06-17 02:01:41 +02:00
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:
commit
c389d79398
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue
Block a user