2015-03-13 98 views
-1

有我的查詢字符串,有沒有關於bindParam的任何問題?Mysql查詢選項參數

$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']); 
+1

優良似乎它沒有成功,爲什麼ü問? – Borik 2015-03-13 17:21:59

+1

你爲什麼覺得有問題?你有錯誤嗎? – Mureinik 2015-03-13 17:31:33

+0

@Mureinik耶,看起來不錯,但運行我的程序,它返回null,實際上有一些記錄存在於我的dasebase – 2015-03-13 17:37:47

回答

0

我發現,參數的類型不爲空,它是字符串的原因,所以當執行下一條語句 (:question is null or B.id=:question)

+0

如果您認爲自己的答案是正確的,請考慮給自己一個綠色複選標記。 – 2016-05-19 02:50:17