Doc #71310 [Ver->Csd]: Can't use DSN with semicolons
[email protected] Thu, 11 Nov 2021 15:17:25 +0000
| Newsgroups | php.doc.bugs |
|---|---|
| Message-ID | <[email protected]> |
Edit report at https://bugs.php.net/bug.php?id=71310&edit=1 ID: 71310 Updated by: [email protected] Reported by: sustmidown at centrum dot cz Summary: Can't use DSN with semicolons -Status: Verified +Status: Closed Type: Documentation Problem Package: PDO PgSQL Operating System: Linux x86-64 PHP Version: 5.6.17 Block user comment: N Private report: N New Comment: Automatic comment on behalf of cmb69 Revision: https://github.com/php/doc-en/commit/1c9673edff353448cea363611229f382c08765d0 Log: Fix #71310: Can't use DSN with semicolons Previous Comments: ------------------------------------------------------------------------ [2021-09-23 13:00:26] [email protected] > Manual page: http://www.php.net/pdo.construct > has no information about how to specify DSN parameters with > special characters. Since this is driver specific, it should be documented in the driver specific documentation[1]; in this case on the PDO_PGSQL DSN page[2]. The PDO_PGSQL driver passes the almost unmodified connection string to PQconnectdb (how this is interpreted is documented in the PostgreSQL manual[3]). However, since PDO DSN strings are usually delimited by semicolons, but PostgreSQL expects space delimited strings, the PDO_PGSQL driver automatically replaces all semicolons with spaces[4], so you cannot connect to databases whose names contain semicolons; this is likely an oversight; OTOH, why would a database name contain a semicolon? I don't think this will be fixed, so I'm changing to doc problem. > […] but according to > https://pear.php.net/manual/en/package.database.db.intro-dsn.php > you should basicly url-encode parameters. What has PEAR:DB to do with PDO? [1] <https://www.php.net/manual/en/pdo.drivers.php> [2] <https://www.php.net/manual/en/ref.pdo-pgsql.connection.php> [3] <https://www.postgresql.org/docs/9.4/libpq-connect.html#LIBPQ-CONNSTRING> [4] <https://github.com/php/php-src/blob/php-7.4.24/ext/pdo_pgsql/pgsql_driver.c#L1207-L1214> ------------------------------------------------------------------------ [2016-01-08 13:01:19] sustmidown at centrum dot cz Description: ------------ Manual page: http://www.php.net/pdo.construct has no information about how to specify DSN parameters with special characters. For example PostgreSQL supports database names containing slash (/) or even semicolon (;). How should I encode DSN dbname parameter to connect to a database named "qwer;asdf"? I tried: $dsn = 'pgsql:host=127.0.0.1;dbname=asdf;asdf'; $dsn = 'pgsql:host=127.0.0.1;dbname=asdf\;asdf'; $dsn = 'pgsql:host=127.0.0.1;dbname=asdf%3basdf'; $dsn = 'pgsql:host=127.0.0.1;dbname=asdf%3Basdf'; but none of those works. If I create database named "asdf/asdf", DSN: $dsn = 'pgsql:host=127.0.0.1;dbname=asdf/asdf'; work, but according to https://pear.php.net/manual/en/package.database.db.intro-dsn.php you should basicly url-encode parameters. But both: $dsn = 'pgsql:host=127.0.0.1;dbname=asdf%2fasdf'; $dsn = 'pgsql:host=127.0.0.1;dbname=asdf%2Fasdf'; do not work. Expected result: ---------------- PDO constructor should support DSN string that contain database name with semicolon in it. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=71310&edit=1