Bug #74767 [NEW]: pg_connect connects to another database

From: Date: Fri, 16 Jun 2017 14:38:40 +0000
Subject: Bug #74767 [NEW]: pg_connect connects to another database
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-209553@lists.php.net to get a copy of this message
From:             ivnpro at mail dot ru
Operating system: Debian Linux
PHP version:      7.0.20
Package:          PostgreSQL related
Bug Type:         Bug
Bug description:pg_connect connects to another database

Description:
------------
pg_connect gives connection resourse to incorrect database.
php.ini default
postgreSQL 9.5 default

using PGSQL_CONNECT_FORCE_NEW help avoid this bug, but too many
connections are opened in production

php-v:
PHP 7.0.20-2~ubuntu14.04.1+deb.sury.org+1 (cli) (built: Jun 14 2017
05:55:23) ( NTS )

Test script:
---------------
<?php

try {
    $count = 0;
    while ($count < 1000) {
        $names = ['test1', 'test2', 'test3', 'test4'];
        $name = $names[mt_rand(0,3)];

        $resource = pg_connect("user=postgres dbname=$name host=db-host
port=5432");
        if (is_resource($resource) && pg_dbname($resource) !==  $name)
{
            /**
             * got it !!!
             */
            echo "count $count \n";
            echo "resource $resource\n";
            echo "is_resource ".is_resource($resource)."\n";
            echo "pg_dbname " .pg_dbname($resource). "\n";
            echo "name $name\n";
            die(1);
        }
        ++$count;
        usleep(1000);
    }
} catch (Exception $e) {
    echo $e . "\n";
}

Expected result:
----------------
empty output if everything correctly, or exception in case couldn't
connect.


Actual result:
--------------
count 26
resource Resource id #23
is_resource 1
pg_dbname test3
name test2

that mean asking for connection to test2, but it gives test3

-- 
Edit bug report at https://bugs.php.net/bug.php?id=74767&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=74767&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=74767&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=74767&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=74767&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=74767&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=74767&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=74767&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=74767&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=74767&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=74767&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=74767&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=74767&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=74767&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74767&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=74767&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=74767&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=74767&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=74767&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=74767&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=74767&r=mysqlcfg



Thread (3 messages)

« previous php.bugs (#209553) next »