简体   繁体   中英

MySQL Can't connect to server on localhost with PHP

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?

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)

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

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM