【问题标题】:connection to ms sql 2005 from php using freetds on centos在 centos 上使用 freetds 从 php 连接到 ms sql 2005
【发布时间】:2012-07-09 19:40:18
【问题描述】:

我在从 PHP 连接到 MS SQL 2005 时遇到问题。

我可以从 shell 连接,使用...

tsql -S 10.0.0.134 -p 1433  -U gareth 

输入一个简单的查询按预期工作...

1> SELECT @@VERSION AS MSSQL_VERSION
2> go
MSSQL_VERSION   
Microsoft SQL Server 2005 - 9.00.4035.00 (Intel X86) 
Nov 24 2008 13:01:59 
Copyright (c) 1988-2005 Microsoft Corporation
Express Edition on Windows NT 6.1 (Build 7601: Service Pack 1)

但是,从 PHP 脚本中尝试此操作不起作用...

$test = mssql_connect('10.0.0.134:1433', 'gareth', 'mypass');

... 并产生一个 mssql_connect() [function.mssql-connect]: Unable to connect to server 错误。

我可以在 /usr/lib/php/modules 中看到 mssql.so 模块,并且 phpinfo() 显示模块已加载。

如果有人可以向我展示 freetds.conf 和 odbc.conf 的示例配置,我会很乐意使用 odbc_connect

谢谢

【问题讨论】:

标签: php sql-server centos freetds


【解决方案1】:

这是我在PHP.net 上可以找到的关于您的问题的信息。也许它会帮助你解决它。

This might be obvious to some, but here is a quick tidbit that might save you some time if you are using FreeTDS in Linux:
Be sure that you have these two lines in freetds.conf:
dump file = /tmp/freetds.log
dump file append = yes

so you can tail -f it in the background of debugging the problem.  This helped me find my issue on on CentOS Linux: 

1) tsql test works

2) php-mssql connection in php also works WHEN RUN FROM THE SHELL

3) running PHP through apache does NOT work.

my /tmp/freetds.log file told me: 
net.c:168:Connecting to MYDBSERVER port MYDBPORT
net.c:237:tds_open_socket: MYDBSERVER:MYDBPORT: Permission denied

and the answer was my firewall/SELinux was denying the Apache processes access to connect to the remote MSSQL DB port, but my shell accounts were fine.

【讨论】:

  • 谢谢!那个调试帮助很大,我发现 SELinux 是导致问题的原因。
  • 我也遇到了同样的问题,这个回复对我有帮助:谢谢!在我的情况下,我简单地解决了:setsebool -P httpd_can_network_connect 1,如下所述:comments.gmane.org/gmane.comp.db.tds.freetds/8627
猜你喜欢
  • 2014-11-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-22
  • 1970-01-01
  • 1970-01-01
  • 2011-03-16
  • 1970-01-01
相关资源
最近更新 更多