Good day. Recently just started learning mysql, therefore. from time to time there are difficulties that I could solve myself up to now. But now I ask for your help.

I'm trying to connect to a mysql server from php, the admin gave me an ip, login, password, database name. Php file looks like this:

$hostname = '192.168.1.20:1433'; $username = "t"; $password = "t"; $dbName = "insy"; mysql_connect($hostname,$username,$password) OR DIE(mysql_error()); mysql_select_db($dbName) or die(mysql_error()); $query = "SELECT * FROM `insy` WHERE 1;"; $result=mysql_query($query) or die(mysql_error()); echo "works!"; mysql_close(); 

When executed, the page hangs for a long time, and eventually returns:

 Warning: mysql_connect() [function.mysql-connect]: MySQL server has gone away in N:\home\192.168.1.19\www\phlib.php on line 12 Warning: mysql_connect() [function.mysql-connect]: Error while reading greeting packet. PID=1908 in N:\home\192.168.1.19\www\phlib.php on line 12 Warning: mysql_connect() [function.mysql-connect]: MySQL server has gone away in N:\home\192.168.1.19\www\phlib.php on line 12 MySQL server has gone away 

12 line is:

 mysql_connect($hostname,$username,$password) OR DIE(mysql_error()); 

I tried in the administration of ODBC Sql Server a data source - with the same parameters it is normally created, the bases are seen.

Tell me what am I doing wrong?

UPD: all machines on Windows.

Thank you in advance!

  • Is Denver worth it or did it put mysql server? the port is just some kind of non-standard 1433. - Artem
  • on the server where I connect - it is worth just a mysql server. A machine with which I connect - with Denver. the port is a working one, you can pick it up with a telnet, unlike the 3306. - rechmp
  • 1433 is the standard MS Sql server port, can there really be another server hanging? phpmyadmin connects to it? - Yura Ivanov
  • Tell me, how can a Mayadmin connect to a remote server? - rechmp
  • one
    And I laughed a lot from this error)) SELECT ... FROM ... // 2 rows, N sec SELECT ... JOIN ... JOIN ... // 5 rows, N sec SELECT ... JOIN .. JOIN ... JOIN ... JOIN ... WHERE ... AND ... AND ... GROUP BY ... LIMIT // Mysql server got offended and left = ( - Sh4dow

1 answer 1

Check that you have remote connections allowed by using the following command:

 %netstat -an | grep 3306 tcp4 0 0 *.3306 *.* LISTEN % 

If you see this line, then remote access is open.

THIS is for FreeBSD, I just don’t know what your server is on! Tell the axis, I will rewrite the command.

Windows

 netstat -na | find "3306" 

LINUX

 netstat -na | grep 3306 
  • cars on windows. check on which of the cars? to connect? It will not work, I do not have access to it. Here is the result from my machine: C: \ Documents and Settings \ omg> netstat -na | find "3306" TCP 0.0.0.0 30 306 0.0.0.0; WISE LISTENING - rechmp
  • what's the point of running on your car ... - Artem
  • Well then all the questions to your admin ... - Artyomich
  • but after all, if you cannot connect to it with a telnet, the port does not obey. the meaning of the net stat ?. - rechmp
  • well then yes! there is no sense from netstat? just above, in the comment it was written by you "with a telnet you can pick up on it, unlike 3306", netstat is possible for any port, I cited port 3306 as an example - Artyomich