[英]Error with Find query in cakephp
CakePHP代碼
$data = $this->DropDownMultiple->find('all',array(
'conditions'=>array('FIND_IN_SET(?,DropDownMultiple.interest)' => array('football')),
'order'=>'created_on desc'
)
);
SQL查詢
SELECT DropDownMultiple.*
FROM `cakephp_tutorial`.`drop_down_multiples` AS `DropDownMultiple`
WHERE FIND_IN_SET('football',`DropDownMultiple`.`interest`) =
ORDER BY `created_on` DESC
語法錯誤
語法錯誤或訪問沖突:1064您的SQL語法有錯誤。 檢查與您的MySQL服務器版本相對應的手冊以獲取正確的語法,以在第1行的“ ORDER BY
created_on
desc”附近使用
問題是在where條件的末尾插入=
符號。 為什么會這樣? 我哪里錯了? 幫我。
您似乎已經設法刪除了我提到的隱藏字符,至少它們不再存在於您在此處顯示的代碼中,盡管不確定您實際使用的代碼。
但是,您使用的不是我顯示的格式:
$data = $this->DropDownMultiple->find('all', array(
'conditions' => array(
'FIND_IN_SET(?, `DropDownMultiple`.`interest`)' => 'football'
),
'order' => 'created_on desc'
)
);
請注意模型和字段名稱兩邊的引號,最重要的是,
。之后的空格。 不確定該空間是否可能是CakePHP中的錯誤。
另請注意,即使在僅包含一個條目的情況下它也可以工作,也無需將值包裝到數組中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.