php.net |  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:
  mysql://database:password@localhost:/path/to/port/mysql.sock/squirrel

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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-30 14:01 UTC] cox@php.net
From http://pear.php.net/manual/en/core.db.tut_dsn.php:

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
mysql://user@unix(/path/to/socket)/pear

Connect to database on a non standard port
pgsql://user:pass@word@tcp(localhost:5555)/pear

Tomas V.V.Cox

PS.- You can use pear-dev@lists.php.net for reporting bugs or pear-general@lists.php.net 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: Thu Dec 05 16:01:30 2024 UTC