|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #18066 Data source name (DSN) parsing bug + FIX
Submitted: 2002-06-29 15:39 UTC Modified: 2002-06-30 18:12 UTC
From: tim-phpbug at bitgems dot com Assigned:
Status: Not a bug Package: PEAR related
PHP Version: 4.2.1 OS: Linux Trustix
Private report: No CVE-ID: None
 [2002-06-29 15:39 UTC] tim-phpbug at bitgems dot com
I'm using a DSN of the format:

Which seemed like it should work, but it fails because of the way PEAR parses the DSN: Instead of looking for the last / to deliniate the database, it looks for the first. I changed the following lines in DB.php, in the function parseDSN, at line 502:

            if (strpos($dsn, '/') !== false) {
                // **THM**
                $offset = strrpos($dsn,'/') ;
                $proto_opts = substr($dsn,0,$offset) ;
                $dsn = substr($dsn,$offset+1);

             //  old: list($proto_opts, $dsn) = explode('/', $dsn, 2);
            } else {


This fixes the problem and should remain compatible with numeric ports as well. A quick scan of the web site didn't reveal how to submit patches, so I hope this is Kosher.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-30 14:01 UTC]

With an up-to-date version of DB, you can use a second DSN format phptype(syntax)://user:pass@protocol(proto_opts)/database example:

Connect to database through a socket

Connect to database on a non standard port

Tomas V.V.Cox

PS.- You can use for reporting bugs or for support questions
 [2002-06-30 18:12 UTC] tim-phpbug at bitgems dot com
Thanks for a quick response. I'll change my configuration to use the new format now that I know about it.

What would be really helpful is if the new format were mentioned in the comment for parseDSN--that was what I was looking at for documentation.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 21 10:02:33 2024 UTC