title: mysql_connect doesn't work with localhost on my Windows machine
body: <p>This does not work with my PHP 5.3.3 installation on WAMP / Windows 7:</p>
  <pre><code>mysql_connect('localhost', 'root', '');
  </code></pre>
  <p>After <code>Maximum execution time</code>, this error is presented:</p>
  <blockquote>
  <p>Warning: mysql_connect() [function.mysql-connect]: [2002] A connection attempt failed because the connected party did not (trying to connect via tcp://localhost:3306)</p>
  <p>Warning: mysql_connect() [function.mysql-connect]: 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.</p>
  </blockquote>
  <p>This works:</p>
  <pre><code>mysql_connect('127.0.0.1', 'root', '');
  </code></pre>
  <p>I'm wondering if it has something to do with this, from the <a href="http://php.net/manual/en/function.mysql-connect.php" rel="nofollow noreferrer">PHP docs</a>:</p>
  <blockquote>
  <p>Whenever you specify &quot;localhost&quot; or &quot;localhost:port&quot; as server, the MySQL client library will override this and try to connect to a local socket (named pipe on Windows). If you want to use TCP/IP, use &quot;127.0.0.1&quot; instead of &quot;localhost&quot;. If the MySQL client library tries to connect to the wrong local socket, you should set the correct path as in your PHP configuration and leave the server field blank.</p>
  </blockquote>
  <p>This is from my php.ini:</p>
  <pre><code>; Default socket name for local MySQL connects.  If empty, uses the built-in
  ; MySQL defaults.
  ; http://php.net/mysql.default-socket
  mysql.default_socket =
  </code></pre>
  <p>Is this a bug, or what is going on?</p>
  <hr />
  <p><strong>Update</strong>: I'm using MySQL 5.1.36 something, and I can connect to it otherwise. Forgot to mention, but this works with PHP 5.3.0 and 5.2.11. Ofcourse I can just change <code>localhost</code> to <code>127.0.0.1</code>, but I want to know why I can't use <code>localhost</code>.</p>
  <hr />
  <p><strong>Update 2</strong>: Adding (uncommenting) <code>127.0.0.1       localhost</code> to the hosts file made it work. But why is this necessary?</p>