]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-17020 dml: native pgsql driver - socket and persistent connection support
authorskodak <skodak>
Tue, 28 Oct 2008 12:03:04 +0000 (12:03 +0000)
committerskodak <skodak>
Tue, 28 Oct 2008 12:03:04 +0000 (12:03 +0000)
lib/dml/pgsql_native_moodle_database.php

index e0634b8107218732f40ce4ed586d774e8a9e999a..fc11b288033357af57786a80e9da264ffd9cf7a2 100644 (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;