简体   繁体   中英

PHP PDO - dblib MSSQL - More complex query issue

my original question outlines my code PHP PDO - dblib MSSQL - using variable in query not working

But now im trying to execute a more complex query. I can get it to work with mssql on the windows server without too much issue, but when i try and copy paste it over to my php page i get nothing.

Im a little confused where i have gone wrong?

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)

Any guidance here would be most appreciated.

You need quotes around your dates. Assuming they're in yyyy-mm-dd format, change the second-to-last line of your query from this:

(dbo_VehicleJobHistory.TimeJobRequired BETWEEN $StartTime AND $FinishTime)

... to this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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