Welcome Guest, Not a member yet? Register   Sign In
Fix to PostgreSQL driver
#1

[eluser]Yoglets[/eluser]
All parameters to the pg_connect() and pg_pconnect() PHP functions are optional, but the CI driver incorrectly assumes that they will all be defined as non-empty in the config file. As a result, it is not possible for CI to connect to a server via Unix domain sockets, which is the default configuration for PostgreSQL.

If "host=" is left out, it will default to Unix domain sockets instead of TCP/IP. If "user=" is left out, it will default to the user making the request. If "dbname=" is left out, it will also default to the user making the request. None of these default actions can be utilized in the current driver however, because it assumes that these values will be provided. Thus, if not provided, the connection string will look like "host= user= dbname=", which is invalid, and not the same as the desired empty connection string. Here is a patch against 1.5.4 to fix:
Code:
--- postgre_driver.php.orig     2007-07-12 06:56:22.000000000 -0500
+++ postgre_driver.php  2007-07-13 16:30:21.000000000 -0500
@@ -38,9 +38,13 @@
         */
        function db_connect()
        {
+               $database = ($this->database == '') ? '' : " dbname=".$this->database;
+               $hostname = ($this->hostname == '') ? '' : " host=".$this->hostname;
                $port = ($this->port == '') ? '' : " port=".$this->port;
+               $username = ($this->username == '') ? '' : " user=".$this->username;
+               $password = ($this->password == '') ? '' : " password=".$this->password;

-               return @pg_connect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password);
+               return @pg_connect($database.$hostname.$port.$username.$password);
        }

        // --------------------------------------------------------------------
@@ -53,9 +57,13 @@
         */
        function db_pconnect()
        {
+               $database = ($this->database == '') ? '' : " dbname=".$this->database;
+               $hostname = ($this->hostname == '') ? '' : " host=".$this->hostname;
                $port = ($this->port == '') ? '' : " port=".$this->port;
-
-               return @pg_pconnect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password);
+               $username = ($this->username == '') ? '' : " user=".$this->username;
+               $password = ($this->password == '') ? '' : " password=".$this->password;
+
+               return @pg_pconnect($database.$hostname.$port.$username.$password);
        }

        // --------------------------------------------------------------------
@@ -482,4 +490,4 @@

}

-?>
\ No newline at end of file
+?>




Theme © iAndrew 2016 - Forum software by © MyBB