简体   繁体   中英

PHP MySQL fails when page is viewed remotely


I have two servers on my local network - one a web frontend and the other a MySQL backend. I have a PHP script that looks like this:

<?php
error_reporting(-1);
echo "Connecting...\n";
$link = mysql_connect("192.168.1.15", "-----", "-----") or die(mysql_error());
echo "Communicating with the server...";

mysql_query("INSERT INTO .....
//More code down here...
?>

This script is called on my web frontend to connect to the backend server. When this script is accessed from the local network (ie when I open the page by going to http://192.168.1.14 ), the script outputs

Connecting...
Communicating with the server...

and a row is added to the database, as it should. However when I connect remotely (ie going to http://myDomainName.com/mysql_insert_script.php ) from a connection not on the local network, all I see is:

Connecting...

No error messages follow, the script just cuts off, and no data is added to the database. When I place a second, 'proxy' script on the server that simply requires() the above script and then I access the proxy remotely, everything works fine. Below is the proxy script, so you can get a better idea of what works and what does not:

<?php
//this script makes it appear that the mysql_script is being viewed from the local network
//I exist on the web frontend at 192.168.1.14
require("http://192.168.1.15/mysql_insert_script.php");
?>

I am sorry if I can't provide any more information, but I am stumped. Any help would be appreciated.

Chris

PS - I have verified that the mysql server is accessible from external hosts on the local network, but I have a firewall that prevents connections from outside my network. I don't think this would matter, however, as the MySQL server and the PHP script connecting to it are both run on the local net.

您输入了错误的服务器名称

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