CodeIgniter Forums
Bug in postgre drivers.. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: Issues (https://forum.codeigniter.com/forumdisplay.php?fid=19)
+--- Thread: Bug in postgre drivers.. (/showthread.php?tid=67934)



Bug in postgre drivers.. - hugo_rune - 04-27-2017

Hi..
 When setting up connect_timeout to postgres I noticed a bug that would cause an error..

Lines 132 to 138 of system\database\drivers\postgre\postgre_driver.php are as follows
PHP Code:
foreach (array('connect_timeout''options''sslmode''service') as $key)
{
    if (isset(
$this->$key) && is_string($this->key) && $this->key !== '')
    {
        
$this->dsn .= $key."='".$this->key."' ";
    }


so if you put a
'connect_timeout' => '5',
into your database config the driver will fail.

Replacing $this->key with $this->$key will fix the issue. For reference...
PHP Code:
foreach (array('connect_timeout''options''sslmode''service') as $key)
{
    if (isset(
$this->$key) && is_string($this->$key) && $this->$key !== '')
    {
        
$this->dsn .= $key."='".$this->$key."' ";
    }


Just in case anyone else notices this issue.


RE: Bug in postgre drivers.. - Paradinight - 04-27-2017

(04-27-2017, 02:42 AM)hugo_rune Wrote: Hi..
 When setting up connect_timeout to postgres I noticed a bug that would cause an error..

Lines 132 to 138 of system\database\drivers\postgre\postgre_driver.php are as follows
PHP Code:
foreach (array('connect_timeout''options''sslmode''service') as $key)
{
 if (isset(
$this->$key) && is_string($this->key) && $this->key !== '')
 {
 
$this->dsn .= $key."='".$this->key."' ";
 }


so if you put a
'connect_timeout' => '5',
into your database config the driver will fail.

Replacing $this->key with $this->$key will fix the issue. For reference...
PHP Code:
foreach (array('connect_timeout''options''sslmode''service') as $key)
{
 if (isset(
$this->$key) && is_string($this->$key) && $this->$key !== '')
 {
 
$this->dsn .= $key."='".$this->$key."' ";
 }


Just in case anyone else notices this issue.

https://github.com/bcit-ci/CodeIgniter/blob/3.1.4/system/database/drivers/postgre/postgre_driver.php#L131
PHP Code:
/* We don't have these options as elements in our standard configuration
* array, but they might be set by parse_url() if the configuration was
* provided via string. Example:
*
* postgre://username:password@localhost:5432/database?connect_timeout=5&sslmode=1
*/
foreach (array('connect_timeout''options''sslmode''service') as $key)
{
    if (isset(
$this->$key) && is_string($this->$key) && $this->$key !== '')
    {
        
$this->dsn .= $key."='".$this->$key."' ";
    }

I do not know why it was wrong in you code, but on the git repo is it right.

edit:
it was fixed in the 3.1.4 Version. https://github.com/bcit-ci/CodeIgniter/issues/5057
Update to the current version.