|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #56383 Connecting to localhost over unix socket doesn't work
Submitted: 2005-04-27 21:14 UTC Modified: 2005-04-28 11:44 UTC
From: murphy at renkoo dot net Assigned:
Status: Closed Package: PDO_MYSQL (PECL)
PHP Version: 5.0.3 OS: Linux and MacOS X
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
14 + 11 = ?
Subscribe to this entry?

 [2005-04-27 21:14 UTC] murphy at renkoo dot net
There's a one line bug in mysql_driver.c in PDO_MYSQL 0.2 which prevents connections to localhost over the local unix socket.

The code tests for the hostname localhost and passes the driver the string "." as the hostname if it matches. However, the mysql C api specifies that the hostname for local socket connections should be "localhost" or NULL.

Here's a patch:

--- mysql_driver.c      Sun Feb  6 15:22:37 2005
+++ mysql_driver.c.patched      Wed Apr 27 17:57:03 2005
@@ -276,7 +276,7 @@
                host = vars[2].optval;
                port = atoi(vars[3].optval); 
        } else {
-               host = ".";
+               host = NULL; 
                unix_socket = vars[4].optval;  
        dbname = vars[1].optval;  

Reproduce code:
$dbh = new PDO("mysql:host=localhost;dbname=mysql",'user','password');
echo "Succeeded.";

Expected result:
The code should successfully connect to the database and print "Succeeded."

Actual result:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2005] Unknown MySQL server host '.' (1)' in /Users/kevin/test.php:2
Stack trace:
#0 /Users/kevin/foo.php(2): PDO->__construct('mysql:host=loca...', 'user', 'password')
#1 {main}
  thrown in /Users/kevin/test.php on line 2   


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-04-27 21:17 UTC] murphy at renkoo dot net
fixed email address
 [2005-04-28 11:44 UTC] george at omniti dot com
This bug has been fixed in CVS.

In case this was a documentation problem, the fix will show up at the
end of next Sunday (CET) on

In case this was a website problem, the change will show
up on the website in short time.
Thank you for the report, and for helping us make PECL better.

Looks fixed in CVS
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jun 18 12:01:29 2024 UTC