|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits              [2007-12-04 13:07 UTC] iliaa@php.net
 | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 01:00:01 2025 UTC | 
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) {