php.net |  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
Description:
------------
I can't connect to "localhost", only to "127.0.0.1". My MySQL server works fine 
and I can connect to it otherwise. PHP 5.3.0 and 5.2.11 work.

Please see http://stackoverflow.com/questions/4015253/php-5-3-3-mysql-connect-
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:
----------------
0-9999

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 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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

Further reading: http://bit.ly/aGVpX8 (which expands to http://blogs.iis.net/donraman/archive/2010/06/11/php-5-3-and-mysql-connectivity-
problem.aspx, which will undoubtedly get mangled by the bug tracker's line 
wrapping).
 [2010-10-26 10:49 UTC] pajoye@php.net
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-2020 The PHP Group
All rights reserved.
Last updated: Tue Oct 20 01:01:23 2020 UTC