PHP PDO - dblib MSSQL - 更复杂的查询问题

时间:2013-03-26 03:40:19

标签: php sql sql-server pdo

我的原始问题概述了我的代码PHP PDO - dblib MSSQL - using variable in query not working

但是现在我试图执行更复杂的查询。我可以在Windows服务器上使用mssql而不会出现太多问题,但是当我尝试将其粘贴到我的php页面时,我什么都没得到。

我有点困惑我出错了?

SELECT 
dbo.VehicleJobHistory.BookingID, dbo.Vehicle.VehicleID, dbo.VehicleJobHistory.DriverID 

FROM 
dbo.Vehicle INNER JOIN dbo.VehicleJobHistory ON dbo.Vehicle.VehicleID = dbo.VehicleJobHistory.VehicleID 

WHERE 
(dbo_VehicleJobHistory.TimeJobRequired BETWEEN $StartTime AND $FinishTime) 
AND (dbo.VehicleJobHistory.VehicleID = $VehicleID)

这里的任何指导都将非常感激。

1 个答案:

答案 0 :(得分:0)

您的日期需要报价。假设它们采用yyyy-mm-dd格式,请从此处更改查询的倒数第二行:

(dbo_VehicleJobHistory.TimeJobRequired BETWEEN $StartTime AND $FinishTime)

......对此:

(dbo_VehicleJobHistory.TimeJobRequired BETWEEN '$StartTime' AND '$FinishTime')