php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #56925 port parameter of DSN does not seem to be honored
Submitted: 2006-03-28 17:36 UTC Modified: 2008-05-08 10:54 UTC
From: php at xmlnode dot com Assigned:
Status: Not a bug Package: PDO_MYSQL (PECL)
PHP Version: 5.1.1 OS: Solaris
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: php at xmlnode dot com
New email:
PHP Version: OS:

 

 [2006-03-28 17:36 UTC] php at xmlnode dot com
Description:
------------
We have two instances of mysql running, 4.1x on port 3306 using /tmp/mysql.sock and 5.0.18 on port 3307 using /tmp/mysql5.0.18/mysql.sock.

If I connect using the dsn and specify the port, like so:
$db = new PDO('mysql:host=localhost;port=3306;dbname=dbname', 'user', 'pass');

I actually connect to the 5.0.18 instance on 3307.  I know this based on the results of the query executed later.  If, however, I connect using the unix_socket parameter and point it at the 3306 socket file, it seems to work correctly.  Again, I know this because the results of the query are correct.

I wouldn't rule out configuration problems on my end, but even if that were the case it would appear you cannot specify a port to override a configuration value

Reproduce code:
---------------
mysql on 3306 (/tmp/mysql.sock)
select count(*) from users;   //result 5

mysql on 3307 (/tmp/mysql5.0.18/mysql.sock)
select count(*) from users;   //result 2

$db = new PDO('mysql:host=localhost;port=3306;dbname=dbname', 'user', 'pass');
$result = $db->query("select count(*) from users");
print_r($result);

//Array ( [count(*)] => 2 [0] => 2 ) //expecting 5

$db = new PDO('mysql:unix_socket=/tmp/mysql.sock;dbname=dbname', 'user', 'pass');
$result = $db->query("select count(*) from users");
print_r($result);

//Array ( [count(*)] => 5 [0] => 5 )


Expected result:
----------------
I expect unix_socket=/tmp/mysql.sock and port=3306 to produce the same results.

Actual result:
--------------
when specifying a port number as part of the dsn it does not seem to be honored.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-04-09 03:20 UTC] wez@php.net
The mysql client library prefers the unix_socket value over the port, and by not specifying a unix_socket, the default that was detected when you configured PHP will be used.

The workaround is to specify a bogus unix_socket when using an alternate port number.
 [2006-10-30 12:56 UTC] gilcher at exozet dot com
You may as well specify the IP adress 127.0.0.1 as hostname instead of localhost. This triggers the mysql client lib to use a TCP connection instead of sockets and the port setting gets honored.
 [2008-05-08 10:53 UTC] johannes at schlueters dot de
For MySQL localhost means "use the unix socket" instead of using TCP/IP therefore the port is ignored so either set another socket in the DSN or use the IP 127.0.0.1 for connecting.
 [2008-05-08 10:54 UTC] johannes at schlueters dot de
See my previous comment
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun May 11 13:01:28 2025 UTC