php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #71310 Can't use DSN with semicolons
Submitted: 2016-01-08 13:01 UTC Modified: 2021-11-11 15:16 UTC
From: sustmidown at centrum dot cz Assigned:
Status: Closed Package: PDO PgSQL
PHP Version: 5.6.17 OS: Linux x86-64
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: sustmidown at centrum dot cz
New email:
PHP Version: OS:

 

 [2016-01-08 13:01 UTC] 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.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-10-24 08:31 UTC] kalle@php.net
-Package: PDO Core +Package: PDO related
 [2021-09-23 13:00 UTC] cmb@php.net
-Status: Open +Status: Verified -Type: Bug +Type: Documentation Problem -Package: PDO related +Package: PDO PgSQL
 [2021-09-23 13:00 UTC] cmb@php.net
> 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>
 [2021-11-11 15:16 UTC] cmb@php.net
-Summary: Not clear how to enter DSN with special characters +Summary: Can't use DSN with semicolons
 [2021-11-11 15:17 UTC] git@php.net
Automatic comment on behalf of cmb69
Revision: https://github.com/php/doc-en/commit/1c9673edff353448cea363611229f382c08765d0
Log: Fix #71310: Can't use DSN with semicolons
 [2021-11-11 15:17 UTC] git@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 16:01:37 2025 UTC