mirror of
https://github.com/silverstripe/silverstripe-postgresql
synced 2024-09-29 12:48:58 +02:00
BUG: Infinite loop on failed connect to a postgresql server
When a postgres db server is down or credentials are wrone, the adapter still tries to check for a existing database and loops back into trying to connect again.
This commit is contained in:
parent
cd7b761bed
commit
201e5b7b8b
@ -147,22 +147,26 @@ class PostgreSQLDatabase extends SS_Database {
|
|||||||
if(self::$check_database_exists) {
|
if(self::$check_database_exists) {
|
||||||
$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->databaseExists($dbName))
|
if(!$this->dbConn) {
|
||||||
|
throw new ErrorException("Couldn't connect to PostgreSQL database");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!$this->databaseExists($dbName)) {
|
||||||
$this->createDatabase($dbName);
|
$this->createDatabase($dbName);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//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);
|
||||||
|
|
||||||
|
if(!$this->dbConn) {
|
||||||
|
throw new ErrorException("Couldn't connect to PostgreSQL database");
|
||||||
|
}
|
||||||
|
|
||||||
//By virtue of getting here, the connection is active:
|
//By virtue of getting here, the connection is active:
|
||||||
$this->active=true;
|
$this->active=true;
|
||||||
$this->database = $dbName;
|
$this->database = $dbName;
|
||||||
|
|
||||||
if(!$this->dbConn) {
|
|
||||||
$this->databaseError("Couldn't connect to PostgreSQL database");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set up the schema if required
|
// Set up the schema if required
|
||||||
$schema = isset($parameters['schema']) ? $parameters['schema'] : $this->currentSchema();
|
$schema = isset($parameters['schema']) ? $parameters['schema'] : $this->currentSchema();
|
||||||
// Edge-case - database with no schemas:
|
// Edge-case - database with no schemas:
|
||||||
|
Loading…
Reference in New Issue
Block a user