If you’re like me, using EasyPHP on Windows 7 for local development and have encountered this PHP/MySQL error:
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 C:\Path\To\Script.php on line 26 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 C:\Path\To\Script.php on line 26 Fatal error: Maximum execution time of 30 seconds exceeded in C:\Path\To\Script.php on line 26
..then you’re in luck! Here’s a quick easy fix:
- Go to “C:\Windows\System32\drivers\etc“.
- Open “hosts” with Notepad program.
- Uncomment this line: “127.0.0.1 localhost” or add it if it’s not on the host entry.
That’s it! Save the changes you’ve made and refresh your browser.
Hope this helps!
* NOTE – Make sure you have a full access on “hosts” file.
- Right click on “hosts” file then click “Properties“.
- On “Security” tab click “Edit…” button.
- Select the user that you are currently using.
- Under “Permissions for Users” box, tick “Full control” on “Allow” column.
- And then click “OK” button to apply the changes.
Not working.
The line has been already uncommented
Your solution works for me. Many thanks!
i have the same issue as well that the line is not commented. checking the file, it contains these following lines:
127.0.0.1 local host
::1 local host
what i did is change the “::1″ into “127.0.0.1″ and that fixed the problem.
hope this fix helps somebody. ^_^
Hi,
You want to leave these lines uncommented as they are necessary for the proper working of your local network:
127.0.0.1 localhost
::1 localhost
MySQL has a bug. It is unable to deal with multiple addresses returned for a single name. Compounding this bug, it is also unable to deal with IPv6 addresses. So when MySQL receives first the IPv6 address for localhost, it times out eventually.
The fix is to replace “localhost” with “127.0.0.1″ in your PHP script.
It worked for me. Thanks a lot!
Thanks a lot
finally I got my Apache-PHP-MySql up n running
Thank you, it was helpful.
thanks very much, it works for me.
This also affected me with Uniform Server.
Ron – do you mean leave the lines in the hosts file commented out? Or uncommented?
replacing the localhost with the ip worked for me…..thank you. I was pulling my hair out.