有我的查询字符串,bindParam有什么问题吗?
$str = "select A.option_id,count(*) as sum
from tb_feedback A,tb_question B,tb_group C
where (A.question_id=B.id)
and (:question is null or B.id=:question)
and (B.group_num=C.id)
and (:group is null or C.name=:group)
and (:fromdate is null or A.date >= CAST(:fromdate AS DATE))
and (:todate is null or A.date <= CAST(:todate AS DATE))
group by A.option_id";
$sql = $this->conn->prepare($str);
$sql->bindParam(':question', $obj['question']);
$sql->bindParam(':group', $obj['group']);
$sql->bindParam(':fromdate', $obj['fromdate']);
$sql->bindParam(':todate', $obj['todate']);
答案 0 :(得分:0)
我找到了参数的类型不是NULL的原因,它是字符串,所以在执行下一个语句时不成功
(:question is null or B.id=:question)