title: PHP MySQL connection failed
body: <p>I am trying to connect my PHP code to MySQL safely with the following code:</p>
  
  <pre><code>&lt;html&gt;
      &lt;?php
          $con = mysql_connect("localhost:3306","root","password");
          if(!$con)
          {
              die('Could not connect: ' . mysql_error());
          }
          else
          {
              echo "Connection established!";
          }
          mysql_close($con);
      ?&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>But I keep getting the following error message:</p>
  
  <blockquote>
    <p>Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on 'localhost' (10061) in C:\xampp\htdocs\database_connect.php on line 5
    Could not connect: Can't connect to MySQL server on 'localhost' (10061)</p>
  </blockquote>
  
  <p>Here are the troubleshooting steps I took:</p>
  
  <ul>
  <li>Checked whether mysqld is running in Windows Task Manager Processes - it is</li>
  <li>Checked whether MySQL was running on the host by typing in Windows command prompt: "telnet 192.0.0.1 3306" and got the message "Could not open connection to the host, on port 3306: connection failed"</li>
  <li>Checked whether Windows Firewall was blocking MySQL - MySQL is an exception.</li>
  </ul>
  
  <p>How do I get this code to work safely? And how do I check basic useful information about my MySQL like username?</p>