2 Votes Vote

PHP MySQL Connection Failed

Posted by topdog 29 days ago Questions| mysql connect php All

Hi,

I am trying to connect my PHP code to MySQL safely with the following code: (how do I put returns?)

<html>
<?php 
$con = mysql_connect("localhost:3306","root","password");
if(!$con)
{
   die('Could not connect: ' . mysql_error());
}
else 
{
   echo "Connection established!"; 
} 
mysql_close($con); 
?> 
</html> 

But I keep getting the following error message:

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)

Here are the troubleshooting steps I took:

  • Checked whether mysqld is running in Windows Task Manager Processes - it is
  • 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"
  • Checked whether Windows Firewall was blocking MySQL - MySQL is an exception.

How do I get this code to work safely? And how do I check basic useful information about my MySQL like username. Any assistance will be appreciated. Thanks in advance.

Discuss Bury


Who Voted for this Question