I have a reasonably simple query that i want to run with my PDO connection to a remote MSSQL server.
SELECT BookingID, DriverID
FROM dbo.VehicleJobHistory
WHERE TimeJobRequired > "02/03/2013" AND VehicleID = $vid
when i write the query without any variables it works perfectly, but as soon as i try to add a variable to the query i get nothing returned. I think its a type mismatch, but i cant be sure.
If i change $vid to "451" i get the results im looking for.
$vid = '451';
$myServer = "X";
$myUser = "X";
$myPass = "X";
$myDB = "X";
try {
# MS SQL Server and Sybase with PDO_DBLIB
$DBH = new PDO("dblib:host=$myServer;dbname=$myDB", $myUser, $myPass);
# creating the statement
$STH = $DBH->query('SELECT BookingID, DriverID FROM dbo.VehicleJobHistory WHERE TimeJobRequired > "02/03/2013" AND VehicleID = $vid');
# setting the fetch mode
$STH->setFetchMode(PDO::FETCH_OBJ);
# showing the results
while($row = $STH->fetch()) {
echo $row->BookingID . "/";
echo $row->DriverID ;
echo "<br>";
}
}
catch(PDOException $e) {
echo $e->getMessage();
}
# close the connection
$DBH = null;
echo "connection closed";
Any help would be most appreciated.