MySQL Can't connect to server on localhost with PHP

你说的曾经没有我的故事 提交于 2019-12-11 03:12:19

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!