Skip to content

Commit

Permalink
Moved parsing of 'host:port' to the constructor (#4165).
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe136 committed Aug 23, 2014
1 parent 816d1c2 commit 2961082
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions libraries/joomla/database/driver/postgresql.php
Expand Up @@ -76,10 +76,16 @@ class JDatabaseDriverPostgresql extends JDatabaseDriver
public function __construct( $options )
{
$options['host'] = (isset($options['host'])) ? $options['host'] : 'localhost';
$options['port'] = (isset($options['port'])) ? $options['port'] : '';
$options['user'] = (isset($options['user'])) ? $options['user'] : '';
$options['password'] = (isset($options['password'])) ? $options['password'] : '';
$options['database'] = (isset($options['database'])) ? $options['database'] : '';

// Fix database with port connection
if(strpos($options['host'], ':')) {
list($options['host'], $options['port']) = explode(':', $options['host'], 2);
}

// Finalize initialization
parent::__construct($options);
}
Expand Down Expand Up @@ -115,16 +121,8 @@ public function connect()
throw new RuntimeException('PHP extension pg_connect is not available.');
}

// Fix database with port connection
$e_host = $this->options['host'];
if(strpos($e_host, ':')) {
list($e_host, $port)=explode(':', $e_host, 2);
} else {
$port=false;
}

// Build the DSN for the connection.
$dsn = "host='$e_host' port='$port' dbname={$this->options['database']} user={$this->options['user']} password={$this->options['password']}";
$dsn = "host='{$this->options['host']}' port='{$this->options['port']}' dbname={$this->options['database']} user={$this->options['user']} password={$this->options['password']}";

// Attempt to connect to the server.
if (!($this->connection = @pg_connect($dsn)))
Expand Down

0 comments on commit 2961082

Please sign in to comment.