From:             jurka at ejurka dot com
Operating system: Debian Unstable
PHP version:      5.2.5
PHP Bug Type:     PDO related
Bug description:  Pdo_pgsql forgets username when given null password

Description:
------------
When creating a PDO object using the pgsql driver, the supplied username
is dropped if the password is null.



Reproduce code:
---------------
$pdo = new PDO('pgsql:host=localhost;port=5777;dbname=mydb', 'myuser');


This will not use the "myuser" username supplied.  Looking at the code in
ext/pdo_pgsql/pgsql_driver.c circa line 695 it says:

        /* support both full connection string & connection string + login
and/or password */
        if (!dbh->username || !dbh->password) {
                spprintf(&conn_str, 0, "%s connect_timeout=%ld", (char *)
dbh->data_source, connect_timeout);
        } else if (dbh->username && dbh->password) {
                spprintf(&conn_str, 0, "%s user=%s password=%s
connect_timeout=%ld", dbh->data_source, dbh->username, dbh->password,
connect_timeout);
        } else if (dbh->username) {
                spprintf(&conn_str, 0, "%s user=%s connect_timeout=%ld",
dbh->data_source, dbh->username, connect_timeout);
        } else {
                spprintf(&conn_str, 0, "%s password=%s
connect_timeout=%ld", dbh->data_source, dbh->password, connect_timeout);
        }

It's trying to cover all the cases of username and password set or not,
but the first condition is wrong.  It should be 

        if (!dbh->username && !dbh->password) {



-- 
Edit bug report at http://bugs.php.net/?id=43493&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=43493&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=43493&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): 
http://bugs.php.net/fix.php?id=43493&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=43493&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=43493&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=43493&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=43493&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=43493&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=43493&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=43493&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=43493&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=43493&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=43493&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=43493&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=43493&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=43493&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=43493&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=43493&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=43493&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=43493&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=43493&r=mysqlcfg

Reply via email to