Just spend a few hours getting Windows 7, Apache, PHP and MySQL up and running.
It should have been fairly easy, but there was a small problem.
While all the subparts worked independendly, PHP was unable to connect to the MySQL database.
MySQL was installed on localhost just to make it easy. However, this is were the trouble began. If you look in the hosts file in Windows 7 (c:\Windows\system32\drivers\etc\hosts) you will notice, that an important line has been commented out:
[sourcecode language=”php”]
# 127.0.0.1 localhost
[/sourcecode]
Now since this line is missing/commented out, PHP can’t find the IP for localhost. Remove the # sign, and save the file. PHP should be able to connect just fine now 🙂
[ad name=”Google Adsense-1″]
As a note, you might run into trouble editing the file. Simply find Notepad in you start menu, right click and select “Run as administrator”. Notepad can now edit and save the changes made to the file.
I hope this blogpost saves someone else a bit of time.
Please, see php.ini, [MySQL] section,
you may setup mysql.default_host variable to 127.0.0.1
And when you try to mysql_connect() define server to 127.0.0.1