I recently upgraded my PHP version to 5.3 and afterwards could not connect to MySQL. I was getting the following error in my PHP error log: PHP Warning: mysql_connect():  A connection attempt failed because the connected party did not (trying to connect via tcp://localhost:3306)
The solution is to do with Windows enabling IPv6 support while MySQL does not support this yet. 'localhost' is being converted to ::1 instead of 127.0.0.1, the solution to this is simple.
Go the the following directory: C:\Windows\System32\drivers\etc
Allow yourself full access to the hosts file by right clicking it and clicking properties.
Next go to the security tab and click the big "Edit" button.
Click on the "Users" group. Below this check the "Full Control" box and then save the changes.
Now that you have access to the file, open the hosts file with a text editor such as notepad.
Comment out the ::1 line with a # so the file will look something like:
# Copyright (c) 1993-2006 Microsoft Corp. #
This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
This file contains the mappings of IP addresses to host names. Each
entry should be kept on an individual line. The IP address should
be placed in the first column followed by the corresponding host name.
The IP address and the host name should be separated by at least one
Additionally, comments (such as these) may be inserted on individual
lines or following the machine name denoted by a '#' symbol.
18.104.22.168 rhino.acme.com # source server
22.214.171.124 x.acme.com # x client host
Once you are done, save the file and try to access your PHP page again that is using MySQL. It should work immedietley.