MDL-17020 dml: native pgsql driver - socket and persistent connection support

This commit is contained in:
skodak 2008-10-28 12:03:04 +00:00
parent 6cc9771844
commit dd2ce45907

View File

@ -86,8 +86,21 @@ class pgsql_native_moodle_database extends moodle_database {
$this->store_settings($dbhost, $dbuser, $dbpass, $dbname, $prefix, $dboptions);
//TODO: handle both port and socket connection
$this->pgsql = pg_connect("host='{$this->dbhost}' user='{$this->dbuser}' password='{$this->dbpass}' dbname='{$this->dbname}'");
$pass = addcslashes($this->dbpass, "'\\");
// Unix socket connections should have lower overhead
if (empty($this->dboptions['forcetcp']) and ($this->dbhost === 'localhost' or $this->dbhost === '127.0.0.1')) {
$connection = "user='$this->dbuser' password='$pass' dbname='$this->dbname'";
} else {
$connection = "host='$this->dbhost' user='$this->dbuser' password='$pass' dbname='$this->dbname'";
}
if (empty($this->dboptions['dbpersit'])) {
$this->pgsql = pg_connect($connection, PGSQL_CONNECT_FORCE_NEW);
} else {
$this->pgsql = pg_pconnect($connection, PGSQL_CONNECT_FORCE_NEW);
}
$status = pg_connection_status($this->pgsql);
if ($status === PGSQL_CONNECTION_BAD) {
$this->pgsql = null;