我的应用程序使用PHP 5.5和MS SQL从数据库和显示中查询某些记录。在SQL服务器上运行时,此查询大约需要2分钟才能执行。
我的问题是mssql_query()
有时会返回NOTHING(即既没有资源ID也没有真或假)。
我预感到这个问题是由于MS SQL超时引起的,但是我没有证明这一点,因为我在php.ini文件中配置了mssql.timeout = 300
(秒)。
有人能帮助我找到根本原因吗?我是php的新手。
SQL查询:
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
SELECT
*
FROM table1 latest
LEFT OUTER JOIN table1 successful
ON latest.MachineVersionID = successful.MachineVersionID
AND successful.BackupToken = (
SELECT TOP 1 BackupToken
FROM table1
WHERE MachineVersionID = successful.MachineVersionID
AND BackupState = 7 AND IsPartial = 0
ORDER BY EndTime DESC
)
INNER JOIN table2 mv ON latest.MachineVersionID = mv.MachineVersionID
INNER JOIN table3 m ON mv.MachineID = m.MachineID
INNER JOIN table4 c ON m.ClientID = c.ClientID
WHERE latest.BackupToken = (
SELECT TOP 1 BackupToken
FROM table1
WHERE MachineVersionID = latest.MachineVersionID
ORDER BY EndTime DESC
)
AND c.PartnerID in (1,2,3,4,5,....)
ORDER BY latest.MachineVersionID