Bug->Doc #71310 [Opn->Ver]: Not clear how to enter DSN with special characters
| From: | cmb@php.net | Date: | Thu, 23 Sep 2021 13:00:26 +0000 |
| Subject: | Bug->Doc #71310 [Opn->Ver]: Not clear how to enter DSN with special characters | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-19208@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=71310&edit=1
ID: 71310
Updated by: cmb@php.net
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