Welcome Guest, Not a member yet? Register   Sign In
CI_DB_postgre_driver->db_connect (and db_pconnect): new connection string logic
#2

[eluser]dathan[/eluser]
Here's a fix to the the previous patch. Apparently when I posted it it had a couple syntax errors.
Code:
Index: postgre_driver.php
===================================================================
--- postgre_driver.php    (revision 1245)
+++ postgre_driver.php    (working copy)
@@ -46,9 +46,18 @@
      */    
     function db_connect()
     {
-        $port = ($this->port == '') ? '' : " port=".$this->port;
-        
-        return @pg_connect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password);
+        $params = array();
+        if ($this->port !== '')
+            $params[] = 'port='.$this->port;
+        if ($this->hostname !== '')
+            $params[] = 'host='.$this->hostname;
+        if ($this->database !== '')
+            $params[] = 'dbname='.$this->database;
+        if ($this->username !== '')
+            $params[] = 'user='.$this->username;
+        if ($this->password !== '')
+            $params[] = 'password'.$this->password;
+        return @pg_connect(implode(" ", $params));
     }

     // --------------------------------------------------------------------
@@ -61,9 +70,18 @@
      */    
     function db_pconnect()
     {
-        $port = ($this->port == '') ? '' : " port=".$this->port;
-
-        return @pg_pconnect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password);
+        $params = array();
+        if ($this->port !== '')
+            $params[] = 'port='.$this->port;
+        if ($this->hostname !== '')
+            $params[] = 'host='.$this->hostname;
+        if ($this->database !== '')
+            $params[] = 'dbname='.$this->database;
+        if ($this->username !== '')
+            $params[] = 'user='.$this->username;
+        if ($this->password !== '')
+            $params[] = 'password'.$this->password;
+        return @pg_pconnect(implode(" ", $params));
     }
    
     // --------------------------------------------------------------------

Mod edit: stuck code inside [code][/code] tags for legibility


Messages In This Thread
CI_DB_postgre_driver->db_connect (and db_pconnect): new connection string logic - by El Forum - 07-01-2008, 12:16 PM



Theme © iAndrew 2016 - Forum software by © MyBB