When I try to connect to my databases, I get this error:
Lost connection to MySQL server at 'reading initial communication packet', system error:111
Here is my PHP code (it's just a test):
@session_start();
include(".conf.php");
print_r($conf);
$con = mysql_connect($conf['db_hostname'], $conf['db_username'], $conf['db_password']) or die (mysql_error());
mysql_select_db("aTableName", $con);
$prof = '000';
//$prof = $_GET['profile'];
$prof = addslashes(htmlentities($prof));
$result = "SELECT * FROM aTableName WHERE id = '$prof'";
$q = mysql_query($result, $con);
$qarr = mysql_fetch_array($q);
print_r($qarr);
?>
Any help would be appreciated. I can't figure it out and it's really bugging me. Thank you!
EDIT: I am hosting on GoDaddy, hosting and databases.
解决方案
Your host is wrong, your port is wrong, a firewall blocked the connection, or the SQL server is not running. 111 is "connection refused". You can troubleshoot by trying to telnet to the SQL server's host and port. If that works, your code gets the host or port wrong.
If that doesn't work, check on the SQL server itself. If it works there, the problem is the network. If it doesn't work there, the SQL server is not running.