Part of the EllisLab Network
   
 
CI_DB_postgre_driver->db_connect (and db_pconnect): new connection string logic
Posted: 30 June 2008 05:29 PM   [ Ignore ]  
Summer Student
Total Posts:  5
Joined  06-30-2008

The connection logic in db_connect and db_pconnect doesn’t give a lot of flexibility in terms of creating the connection string.  So I modified it to only use whichever DB connection parameters the user actually supplied to create the connection string (motivated by my server config, in which I just have to give the dbname parameter and the apache account is authenticated by the system with no additional credentials).  I’ve only tested it with database settings set in the application/config/database.php file.

Here’s a unified DIFF of the database/drivers/postgre/postgre_driver.php file:

-----===== Removed for brevity.  See next post for updated version. =====-----

Profile
 
 
Posted: 01 July 2008 01:16 PM   [ Ignore ]   [ # 1 ]  
Summer Student
Total Posts:  5
Joined  06-30-2008

Here’s a fix to the the previous patch.  Apparently when I posted it it had a couple syntax errors.

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

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 719, on June 06, 2008 10:16 AM
Total Registered Members: 61066 Total Logged-in Users: 15
Total Topics: 73889 Total Anonymous Users: 0
Total Replies: 398542 Total Guests: 327
Total Posts: 472431    
Members ( View Memberlist )
Newest Members:  KarnadvdconsultingindispusTelder4336dudeami0Dale-M Moeen uddinbnolenstanjadebieSan2k
Active Members:    Adrian PopescuAuroCraig RodwayCrucialexodus7JemgamesKarnaLuci3nmarcossmcrafalphpoetPopcornScriptorsocsTom Glover