|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53162 Can't use localhost without mapping it in hosts
Submitted: 2010-10-26 09:01 UTC Modified: 2010-10-26 10:53 UTC
From: znarkus at gmail dot com Assigned:
Status: Duplicate Package: *Database Functions
PHP Version: 5.3.3 OS: Windows 7 x64
Private report: No CVE-ID: None
 [2010-10-26 09:01 UTC] znarkus at gmail dot com
I can't connect to "localhost", only to "". My MySQL server works fine 
and I can connect to it otherwise. PHP 5.3.0 and 5.2.11 work.

Please see
doesnt-work-with-localhost for more details.

Test script:
mysql_connect('localhost', 'root', '');

new mysqli('localhost', 'root', '');

new PDO('mysql:dbname=db_name;host=localhost', 'root', '');

die('' . rand(0, 9999));

Expected result:

Actual result:
Warning: mysql_connect() [function.mysql-connect]: [2002] A connection attempt 
failed because the connected party did not (trying to connect via 
tcp://localhost:3306) in

Warning: mysql_connect() [function.mysql-connect]: A connection attempt failed 
because the connected party did not properly respond after a period of time, or 
established connection failed because connected host has failed to respond. in 

Fatal error: Maximum execution time of 30 seconds exceeded in 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-10-26 09:31 UTC]
-Status: Open +Status: Duplicate
 [2010-10-26 09:31 UTC]
Dupe of many, many bugs, most recently bug #52516.

Further reading: (which expands to
problem.aspx, which will undoubtedly get mangled by the bug tracker's line 
 [2010-10-26 10:49 UTC]
The IIS post is not totally correct.

Also the IPv6 vs IPv4 issue has been fixed and will be present in 5.3.4+
 [2010-10-26 10:53 UTC] znarkus at gmail dot com
What I don't understand is why this works in PHP 5.3.0 with the same MySQL server. If the problem lies with MySQL, shouldn't it be consistent on all versions of PHP?
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sun Jun 26 08:05:45 2022 UTC