简体   繁体   English

Apache PHP脚本无法连接到远程数据库/ ODBC / MySQL,但可以从命令行运行

[英]Apache PHP script can't connect to remote database/ODBC/MySQL but works from command line

Using Windows Vista system with Apache 2.2 and PHP 5. 将Windows Vista系统与Apache 2.2和PHP 5配合使用。

I have a script that tests connections to various ODBC and MySQL databases. 我有一个脚本,用于测试与各种ODBC和MySQL数据库的连接。 When the script runs from Apache loaded in a browser window it cannot connect to any remote ODBC or MySQL databases. 当脚本从浏览器窗口中加载的Apache运行时,它无法连接到任何远程ODBC或MySQL数据库。 Local databases work fine. 本地数据库工作正常。 Socket connection also does not work. 套接字连接也不起作用。

When I run from the command prompt, all connections are OK. 当我从命令提示符运行时,所有连接都可以。

When testing the connection in the ODBC control panel, they also work fine. 在ODBC控制面板中测试连接时,它们也可以正常工作。 Other applications on different systems on our network can connect to these databases. 我们网络上不同系统上的其他应用程序可以连接到这些数据库。

Also, I am able to run this script from a browser window served from Apache installed under Windows on another system in a remote location. 另外,我能够从浏览器窗口中运行此脚本,该浏览器窗口是由Apache在远程位置的另一个系统上的Windows下提供的。

The Windows Apache server system has the firewall disabled, but it is behind a network firewall/proxy. Windows Apache服务器系统已禁用防火墙,但它位于网络防火墙/代理之后。 Although since the script works in command line, so I don't think its a firewall issue. 尽管由于脚本可以在命令行中运行,所以我认为它不是防火墙问题。

I have seen solutions for this but they are for Linux systems, I can't find anything for Windows machines. 我已经看到了解决方案,但是它们是针对Linux系统的,对于Windows计算机,我找不到任何解决方案。

Can this be some setting in the php.ini or http.conf files? 可以在php.ini或http.conf文件中进行一些设置吗? Is this some Windows setting? 这是Windows的设置吗?

Here is the code 这是代码

$lmSock = fSockOpen('www.server.com',80, $errno, $errstr, 30);
if(!$lmSock) {
echo("Can't open Remote socket<br />\n");
}
else {
echo("Remote Socket Success<br />\n");
}    

$odbcConn = odbc_connect('remote.mysql','','');
if(!$odbcConn) {
    echo("Cannot Connect To ODBC remote.mysql Server<br />\n");
}
else {
  echo("ODBC remote.mysql Connection success<br />\n");
}

$odbcConn = odbc_connect('local.sql','','');
if(!$odbcConn) {
    echo("Cannot Connect To ODBC local.sql Server<br />\n");
}
else {
  echo("ODBC local.sql Connection success<br />\n");
}

$toyConn = odbc_connect('remote.sql','','');
if(!$toyConn) {
    echo("Cannot Connect To ODBC remote.sql Server<br />\n");
}
else {
  echo("ODBC remote.sql Connection success<br />\n");
}

$mysqlConn = mysql_connect('server.address','login','pass');
if(!$mysqlConn) {
    echo("Cannot Connect To MYSQL server.address Server<br />\n");
}
else {
  echo("MYSQL server.address Connection success<br />\n");
}

The first thing I would check is to make sure that your connection is not being blocked by Windows Firewall. 我要检查的第一件事是确保Windows防火墙不会阻止您的连接。 Try temporarily disabling it just to test. 尝试暂时禁用它以进行测试。

Turn Windows Firewall on or off 打开或关闭Windows防火墙

If that does not help, you may want to try downloading WAMP to see if there is something wrong with your installation. 如果这样做没有帮助,则可能需要尝试下载WAMP,以查看安装是否存在问题。 I am not suggesting you replace your existing installation (although you might want to if it works), I am suggesting this to try to determine if there is something wrong with the installation, or your OS. 我不建议您替换现有的安装(尽管您可能希望这样做),但我建议这样做是为了确定安装或操作系统是否存在问题。

WAMP Download WAMP下载

The problem was our company firewall. 问题是我们公司的防火墙。 (Microsoft ISA Server 2000). (Microsoft ISA Server 2000)。

This firewall uses a utility (ISA Client) installed on our internal systems including the server all this is running on. 该防火墙使用安装在我们内部系统(包括正在运行的所有服务器)上的实用程序(ISA客户端)。

It seems to me that the command line PHP scripts and ODBC control panel work through this client. 在我看来,命令行PHP脚本和ODBC控制面板可通过此客户端运行。 Unfortunately for some reason Apache does not. 不幸的是,由于某些原因,Apache没有这么做。

Resolved this by using the MySQL proxy application, it mirrors the remote database to a local IP address. 通过使用MySQL代理应用程序解决了此问题,它将远程数据库镜像到本地IP地址。 The proxy application runs from the command line and seems to work with the firewall client. 代理应用程序从命令行运行,并且似乎可以与防火墙客户端一起使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM