Skip to content
This repository

Update libraries/joomla/database/driver/postgresql.php #1838

Closed
wants to merge 3 commits into from

3 participants

jdeproost Andrew Eddie Don Gilbert
jdeproost

Take into account that pg_connect() takes the port as separate argument.

Andrew Eddie

There are a few code style problems with this PR. Would you mind fixing them. Thanks.

http://developer.joomla.org/pulls/pulls/1838.html

jdeproost
Don Gilbert
Owner

Any tests we could implement to protect this from causing regressions when merged? Need to make sure not to break anything existing.

Don Gilbert
Owner

This is currently unmergeable. Please rebase your changes from staging and then reopen the pull request by leaving a comment "reopen"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 3 unique commits by 1 author.

Feb 20, 2013
jdeproost jdeproost Update libraries/joomla/database/driver/postgresql.php
Take into account that pg_connect() takes the port as separate argument.
d298e5f
jdeproost jdeproost Update libraries/joomla/database/driver/postgresql.php 9e9d8f6
Mar 15, 2013
jdeproost jdeproost Update postgresql.php
fixed warnings
bbe57f0
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 37 additions and 1 deletion. Show diff stats Hide diff stats

  1. +37 1 libraries/joomla/database/driver/postgresql.php
38 libraries/joomla/database/driver/postgresql.php
@@ -72,6 +72,8 @@ public function __construct( $options )
72 72 $options['user'] = (isset($options['user'])) ? $options['user'] : '';
73 73 $options['password'] = (isset($options['password'])) ? $options['password'] : '';
74 74 $options['database'] = (isset($options['database'])) ? $options['database'] : '';
  75 + // Check if port is set during construction
  76 + $options['port'] = (isset($options['port'])) ? $options['port'] : null;
75 77
76 78 // Finalize initialization
77 79 parent::__construct($options);
@@ -110,9 +112,43 @@ public function connect()
110 112 {
111 113 throw new RuntimeException('PHP extension pg_connect is not available.');
112 114 }
  115 + /*
  116 + * pg_connect() takes the port as separate argument. Therefore, we
  117 + * have to extract it from the host string (if povided).
  118 + */
  119 +
  120 + // Check for empty port
  121 + if (!($this->options['port']))
  122 + {
  123 + // Port is empty, check for port annotation (:) in the host string
  124 + $tmp = substr(strstr($this->options['host'], ':'), 1);
  125 +
  126 + if (!empty($tmp))
  127 + {
  128 + // Get the port number
  129 + if (is_numeric($tmp))
  130 + {
  131 + $this->options['port'] = $tmp;
  132 + }
  133 +
  134 + // Extract the host name
  135 + $this->options['host'] = substr($this->options['host'], 0, strlen($this->options['host']) - (strlen($tmp) + 1));
  136 +
  137 + // This will take care of the following notation: ":5432"
  138 + if ($this->options['host'] == '')
  139 + {
  140 + $this->options['host'] = 'localhost';
  141 + }
  142 + }
  143 + // No port annotation (:) found, assuming default PostgreSQL port 5432
  144 + else
  145 + {
  146 + $this->options['port'] = '5432';
  147 + }
  148 + }
113 149
114 150 // Build the DSN for the connection.
115   - $dsn = "host={$this->options['host']} dbname={$this->options['database']} user={$this->options['user']} password={$this->options['password']}";
  151 + $dsn = "host={$this->options['host']} port={$this->options['port']} dbname={$this->options['database']} user={$this->options['user']} password={$this->options['password']}";
116 152
117 153 // Attempt to connect to the server.
118 154 if (!($this->connection = @pg_connect($dsn)))

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.