mirror of
https://github.com/silverstripe/silverstripe-postgresql
synced 2024-09-29 20:59:01 +02:00
ENHANCEMENT: added option to disable checking of database existence before querying it. Needs to be disabled to allow it to work under multi user environments
This commit is contained in:
parent
8032985b1a
commit
c6e0714c62
@ -11,6 +11,7 @@
|
|||||||
* @subpackage model
|
* @subpackage model
|
||||||
*/
|
*/
|
||||||
class PostgreSQLDatabase extends SS_Database {
|
class PostgreSQLDatabase extends SS_Database {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connection to the DBMS.
|
* Connection to the DBMS.
|
||||||
* @var resource
|
* @var resource
|
||||||
@ -53,6 +54,15 @@ class PostgreSQLDatabase extends SS_Database {
|
|||||||
|
|
||||||
private $supportsTransactions=true;
|
private $supportsTransactions=true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether to check a database exists on the host by
|
||||||
|
* querying the 'postgres' database and running createDatabase.
|
||||||
|
*
|
||||||
|
* Some locked down systems prevent access to the 'postgres' table in
|
||||||
|
* which case you need to set this to false.
|
||||||
|
*/
|
||||||
|
public static $check_database_exists = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connect to a PostgreSQL database.
|
* Connect to a PostgreSQL database.
|
||||||
* @param array $parameters An map of parameters, which should include:
|
* @param array $parameters An map of parameters, which should include:
|
||||||
@ -90,9 +100,13 @@ class PostgreSQLDatabase extends SS_Database {
|
|||||||
$port = empty($parameters['port']) ? 5432 : $parameters['port'];
|
$port = empty($parameters['port']) ? 5432 : $parameters['port'];
|
||||||
|
|
||||||
// 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
|
||||||
|
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->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);
|
||||||
|
Loading…
Reference in New Issue
Block a user