简体   繁体   English

mssql_query不返回任何内容

[英]mssql_query doesn't return anything

I am having problems with setting up a system. 我在建立系统时遇到问题。

We have a SQL Server 2005 running and I want to connect it from another windows machine running php 5.2 and apache. 我们有一个正在运行的SQL Server 2005,我想从另一台运行php 5.2和apache的Windows机器上连接它。

I can connect to SQL using mssql_connect but I can not retrieve any results from a simple query (SELECT * FROM USERS) mssql_query doesnt return anything nor dies or shows an error. 我可以使用mssql_connect连接到SQL,但无法从简单查询(SELECT * FROM USERS)中检索任何结果。mssql_query不返回任何内容,也不会死亡或显示错误。

Same code with same php is working on another machine (client of SQL Server machine) and in the PC running SQL Server. 具有相同php的相同代码正在另一台计算机(SQL Server计算机的客户端)和运行SQL Server的PC中工作。

What could be going on? 可能会发生什么?

It may be timing out due to longer time to execute the query? 由于执行查询的时间较长,可能会超时? You could try a simpler query like SELECT 1 您可以尝试更简单的查询,例如SELECT 1

If it is a timeout issue, you may have to look into why does it happen to this computer...or you may be able to fix it by having this line in code before the query executes: ini_set('mssql.timeout', seconds) where seconds is a number. 如果是超时问题,则可能必须调查这台计算机为何会发生这种情况...或者您可以通过在执行查询之前在代码中包含以下行来修复它: ini_set('mssql.timeout', seconds) ,其中秒是数字。

我以前从未使用过MsSQL,但尝试在文件顶部设置error_reporting(E_ALL) ,然后在调用mssql_query()执行var_dump(mssql_get_last_message())

If the query just hangs, then probably the table is locked. 如果查询只是挂起,则表可能已锁定。

Could you please run a query that does not involve any tables (like mere SELECT 1 ) and see if it works? 您能否运行一个不包含任何表的查询(例如SELECT 1 ),看看它是否有效?

I would start with configuration. 我将从配置开始。 If it's working fine from another machine and this is the only one with an issue then 如果它可以在另一台机器上正常工作,并且这是唯一有问题的机器,那么
1. Compare drivers between the working / non-working machines. 1.比较工作/非工作机器之间的驱动程序。
2. Compare php installations. 2.比较php的安装。

You get the picture. 您得到图片。

Also, I'm not sure what you mean by "(client of SQL Server machine)"... 另外,我不确定您所说的“((SQL Server计算机的客户端)”)是什么意思...

Thanks everybody, I solved it. 谢谢大家,我解决了。 There was a upper/lowercase mistake on my php code, and I was not treating any rows of the resultset. 我的php代码中存在一个大写/小写错误,并且我没有处理结果集的任何行。

It took me hours to notice this stupid thing! 我花了几个小时才注意到这个愚蠢的事情!

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

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