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.
Hi guys I’m having the same problem as Alex unfortunately I am a real beginner so not sure what your talking about in your replies I am assuming that for the mysqli_connect you need to change the code on the index.php file within the connect folder tried that and it didn’t work I changed the password to the password i created in mysqladmin still getting error message any ideas please would be gratefully received.
Hi Space Phoenix, thanks for the quick response I’m not sure how I’m supposed to run that php script I assumed you put it into an html page and got nothing back, when I check my apache server is says its running and it shows on the bottom Apache/2.2.13(win32) PHP/5.3.0 realise that perhaps someone so thick shouldn’t be trying to write database driven websites but I love a challenge. once again thanks for the help any ideas on where to go from here (please don’t suggest Siberia! I hate the cold.)
thanks again for the prompt reply didn’t spot my obvious mistake changed the page to php and I get a page that shows PHP Version 5.3.0 with a big list of what is enabled etc then below that configuration with apache2handler followed by lots of other bits and pieces. once again thanks for the reply
Fortunately I am running a mac as well as windows machine and managed to get MAMP up and running which made the whole process a lot simpler, I found a good PHP text editor which is free for windows and mac called komodo it highlights the code for you and if you get wamp up and running you can use it to follow the course. Hope this.
yep it is, I just did a reboot and now I have a different error:
“Warning: mysqli_connect() [function.mysqli-connect]: (/838860800): in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 2
Unable to connect to the database server.”
which I am guessing just means my password is wrong, had trouble with that cmd in the book too… hmm
final edit: yep, ‘Database connection established.’
reboot and a change of the pw in my code did it. thanks!
I had the same issue as above, Fatal error: Call to undefined function mysqli_connect() in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 2.
I updated PHP as suggested and it seemed to solve the problem one time. I now get a 500 error on the web page. It doesn’t happen instantly it seems to take a minute or so. I know that the localhost, user name, and password are correct.
Error: The website cannot display the page
Most likely causes:
•The website is under maintenance.
•The website has a programming error.
What you can try:
Refresh the page.
Go back to the previous page.
I am on a Windows 7 box, using Apache 2.2, PHP Version 5.3.2, MySQL 5.1.
I used php-5.3.2-Win32-VC6-x86 for Apache.
I just got:
Warning: mysqli_connect() [function.mysqli-connect]:  A connection attempt failed because the connected party did not (trying to connect via tcp://localhost:3306) in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 2
Warning: mysqli_connect() [function.mysqli-connect]: (HY000/2002): 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:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 2
Fatal error: Maximum execution time of 30 seconds exceeded in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 2