When i run this query in phpmyadmin
it runs fine and returns what it should return.
When i run it in php
with PDO
it fails. Can someone tell me why? The error message shows that the right parameters were used.
Code i run in phpmyadmin
.
SELECT `fd1`.`id` , `fd2`.`id` , `fd3`.`id`
FROM `food` AS `fd1` , `food` AS `fd2` , `food` AS `fd3`
WHERE `fd1`.`food` = 'Empty'
AND `fd2`.`food` = 'Carrot'
AND `fd3`.`food` = 'Empty'
Code i run in php
$sql = 'SELECT `fd1`.`id` , `fd2`.`id` , `fd3`.`id`
FROM `food` AS `fd1` , `food` AS `fd2` , `food` AS `fd3`
WHERE `fd1`.`food` = ?
AND `fd2`.`food` = ?
AND `fd3`.`food` = ?';
$stmt = $db->prepare($sql);
$stmt->bindParam(1, $food1, PDO::PARAM_STR);
$stmt->bindParam(2, $food2, PDO::PARAM_STR);
$stmt->bindParam(3, $food3, PDO::PARAM_STR);
$stmt->execute();
if (!$stmt->rowCount())
die("ERROR:FOOD_SEARCH_FAILURE food:$food1, $food2, $food3 rows returned". $stmt->rowCount());
I also tried to run it with:
$stmt->execute(array($food1, $food2, $food3));
Same results