当我在其中运行此查询时,phpmyadmin
它运行良好并返回它应该返回的内容。
当我运行它时php
它PDO
失败了。有人能告诉我为什么吗?错误消息显示使用了正确的参数。
我运行的代码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'
我运行的代码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());
我还尝试使用以下命令运行它:
$stmt->execute(array($food1, $food2, $food3));
相同的结果