2
votes

My php code fails to connect to the mysql database on my web server. I get the following error:

mysql_connect(): Lost connection to MySQL server at 'reading initial communication packet', system error: 110 in filename at line 71.

The same code works fine when run from my development machine pointed at the mysql database on the server I'm trying to run this from (I copied the file up to the server and I'm trying to run it via ssh on that server). I have verified that the mysql user in the script can connect to the database from the server by running mysql from the ssh command line on that server using the same user name and password as specified in my php script.

here is my code:

function jsw_set_cnxn($env){
        global $env;
        $cnxn = mysql_connect($env['db_svr'], $env['db_usr'], $env['db_pwd']) 
               or die ('DB Connection Error: ' . mysql_error());
        mysql_select_db ($env['db'], $cnxn);
    return $cnxn;
}
1
googling a little shows a lot of results on the subject. this is one of the links that may help you out: forums.mysql.com/read.php?52,152265,152265marcelog
@Charles - I saw that question when I searched, it did not helpScott
@marcelog I googled first, and checked out many forum posts including the one you mentioned. Nothing fit exactly.Scott
I should mention that there are several php web sites on this server and they all connect with no problem using essentially the same code.Scott

1 Answers

1
votes

I've seen this error caused when using the servers IP address when it expects localhost as the server address.

This is because the server is the machine mysql expects but the wrong host coming in. Try using localhost.