I had the same problem in Windows 7. The error message began "Warning: mysql_connect() [function.mysql-connect]:  A connection attempt failed because the connected party did not (trying to connect via tcp://localhost:3306)"
I only found the solution by reading various snippets of advice in different places. Here is the way to fix this problem, all in one place:
First, close all open programs. I stopped the Apache service and the mysql service using Windows Task Manager (click on the services tab and then on the services button in the lower right corner. Find the services in the list and select and stop each in turn.)
Next, run Notepad as administrator. To do that, find Notepad in the Windows Start menu, right click the icon and select Run as Administrator. Now, navigate to C:\Windows\System32\drivers\etc and find and open the hosts file.
Find the line that looks like this:
Uncomment that line by removing the # from the line and then save the hosts file. Close Notepad and then restart Windows.
This worked for me. Good luck. Thanks to Patrício dos Santos in the mysql forums for most of this.