FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » FUDforum Development » Plugins and Code Hacks » Database host:port support
Show: Today's Messages :: Unread Messages :: Show Polls :: Message Navigator
| Subscribe to topic | Bookmark topic 
Switch to threaded view of this topic Create a new topic Submit Reply
Database host:port support [message #163964] Fri, 17 December 2010 07:57 Go to next message
mguillaume is currently offline  mguillaume   France
Messages: 13
Registered: December 2010
Karma: 0
Junior Member
add to buddy list
ignore all messages by this user
Right now we don't have support for non-standard db ports (at least in PostgreSQL) though the GLOBALS_HELP suggest we should be able to use the "host:port" notation for the db host.

Suggestion: in data/sql/pgsql/db.inc, replace:
if ($GLOBALS['DBHOST']) {
    $connect_str .= 'host='. $GLOBALS['DBHOST'];
}

with:
if ($GLOBALS['DBHOST']) {
    $hostport=explode(":",$GLOBALS['DBHOST']);
    if (count($hostport)==1) {
        $connect_str .= 'host='. $GLOBALS['DBHOST'];
    } else {
        $connect_str .= 'host='.$hostport[0].' port='.$hostport[1];
    }
}


Note that this probably should be improved upon to support IPv6 addresses (which include ':' in their notation).
Re: Database host:port support [message #163965 is a reply to message #163964] Sat, 18 December 2010 18:19 Go to previous messageGo to next message
naudefj is currently offline  naudefj   South Africa
Messages: 3632
Registered: December 2004
Karma: 17
Senior Member
Administrator
Core Developer
add to buddy list
ignore all messages by this user
Can you please test the below code (with IPv6 support)?
if ($GLOBALS['DBHOST']) {
        // Expand optional port number (e.g. [::1]:5432).
        if ( preg_match('/^(.+):(\d*)$/', $GLOBALS['DBHOST'], $m)) {
                $GLOBALS['DBHOST'] = $m[1] .' port='. $m[2];
        }
        // Remove IPv6 block quotes.
        $connect_str .= preg_replace('/\[|\]/', '', 'host='. $GLOBALS['DBHOST']);
}
Re: Database host:port support [message #163967 is a reply to message #163965] Sat, 18 December 2010 23:46 Go to previous messageGo to next message
Ernesto is currently offline  Ernesto   Sweden
Messages: 413
Registered: August 2005
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
Do you really wanna redefine a global variable in the 4th row instead of using a placeholder Frank?

Re: Database host:port support [message #163968 is a reply to message #163967] Sun, 19 December 2010 00:09 Go to previous messageGo to next message
naudefj is currently offline  naudefj   South Africa
Messages: 3632
Registered: December 2004
Karma: 17
Senior Member
Administrator
Core Developer
add to buddy list
ignore all messages by this user
Maybe not. We should to use a placeholder Smile
Re: Database host:port support [message #163970 is a reply to message #163968] Sun, 19 December 2010 09:17 Go to previous message
naudefj is currently offline  naudefj   South Africa
Messages: 3632
Registered: December 2004
Karma: 17
Senior Member
Administrator
Core Developer
add to buddy list
ignore all messages by this user
Patch committed.
Details at http://fudforum.svn.sourceforge.net/fudforum/?rev=5090&view=rev
Quick Reply
Formatting Tools:   
  Switch to threaded view of this topic Create a new topic
Previous Topic: Suggestion for the "rebuild search index" page
Next Topic: Logging Group Manager actions
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Dec 16 00:31:45 EST 2017

Total time taken to generate the page: 0.00742 seconds