问题
I'm using XAMPP 1.7.2 and can connect to MySQL via cmd and SQLYog, but not programmatically.
This PHP code:
$conn = mysql_connect('localhost', 'root', '*****');
if (!$conn) {
die('Could not connect: '. mysql_error());
}
gives me:
mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on 'localhost' (10013) in C:\test\login.php on line 10
Could not connect: Can't connect to MySQL server on 'localhost' (10013)
How do I debug this issue?
回答1:
Your connection shows an Error #10013. It's basically a firewall problem or socket error. Maybe your mysql setup is not on default port? (which is 3306)
回答2:
This might be a hint to your problem. Not sure if it is. In the following post, i read that there maybe your firewall that preventing your connection. Try disabling your firewall and see if u can connect. If you can, then configure your firewall differently.
Reference http://forums.mysql.com/read.php?10,152798
回答3:
Occasionally 127.0.0.1 will work instead of localhost. Same location, just a different reference to it.
A basic thing to check is that all the login credentials are correct. Have the right user/pass/dbName?
来源:https://stackoverflow.com/questions/9753285/mysql-cant-connect-to-server-on-localhost-with-php