I was moving WordPress from Windows Vista and PHP 5.2 to Windows 7 and PHP 5.3 when I encountered what appeared to be a page timeout resulted in Apache HTTP Server rendering a blank page back to the browser. Initial Google sessions did not help, so I dove into the code. After some digging I found the timeout was happening in the wpdb class, the constructor method when it was making the following call:
520 | $this->dbh = @mysql_connect( $dbhost, $dbuser, $dbpassword, true ); |
For those of you not familiar with the @ symbol’s use in PHP let’s just say that in simple terms it prevents error messages from being displayed. I assume this is here to prevent UID and PWD from leaking out, but it also prevented me from knowing that the problem was with my MySQL connection until I traced this statement down. Annoying.
Armed with this knowledge I was able to do some more intelligent searching. First I looked up the mysql_connect function. Down in the comments there was a very helpful comment by Bruce Kirkpatrick that explained what was causing the issue. The new behavior of mysql_connect was relying on my hosts file to resolve localhost on Windows 7. This was based on the change not from Windows Vista to Windows 7, but on the change of PHP 5.2 to PHP 5.3.
So I opened my trusty text editor as administrator, navigated to where the hosts files should be and nothing was there. Even the etc directory was missing. I checked out the Wikipedia article on the Hosts (file) and discovered that users of Windows 64 bit OS’s (other than Windows 7) could not access the hosts file with a 32 bit editor. Since my editor is 32 bit, I could navigate as far as c:\windows\system32\drivers\ and then I could not see the hosts file. So what I did was type in etc\hosts in the file open dialog box and it opened as expected. I then uncommented the following line by removing the # symbol at the start of the line.
1 | 127.0.0.1 localhost |
I saved my changes and tested my blog site again using localhost and it worked perfectly. It worked so well that the post you are reading was the first that I penned on my blog’s new server. If you run into a similar problem I hope that this post can save you some time.

