Bug->Doc #71310 [Opn->Ver]: Not clear how to enter DSN with special characters

[email protected]
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:            Not clear how to enter DSN with special characters
-Status:             Open
+Status:             Verified
-Type:               Bug
+Type:               Documentation Problem
-Package:            PDO related
+Package:            PDO PgSQL
 Operating System:   Linux x86-64
 PHP Version:        5.6.17
 Block user comment: N
 Private report:     N

 New Comment:

> 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>


Previous Comments:
------------------------------------------------------------------------
[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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.