我試圖生成從那裏名字的姓的任意組合相匹配的特定搜索字詞Zend Framework的SQL SELECT查詢建設(WHERE子句)
$select = $select->where('last_name LIKE ?', '%'.$term.'%')->orWhere('first_name LIKE ?', '%'.$term.'%')
->orWhere("CONCAT(first_name,' ', last_name) LIKE ?", '%'.$term.'%')
->orWhere("CONCAT(last_name,' ', first_name) LIKE ?", '%'.$term.'%');
有一個用戶表中選擇的所有查詢就是有也必須滿足它在另一個where子句
$select = $select->where("deleted = 0 AND scholar = 0");
下面的SQL語句生成
SELECT `user`.* FROM `user` WHERE (last_name LIKE '%frank%') OR (first_name LIKE '%frank%') OR (CONCAT(first_name,' ', last_name) LIKE '%frank%') OR (CONCAT(last_name,' ', first_name) LIKE '%frank%') AND (deleted = 0 AND scholar = 0) ORDER BY `date_created` desc LIMIT 25
規定的其他條件
這不會返回所需的結果,因爲我得到的行在哪裏scholar = 1;
我想通查詢應該是
SELECT `user`.* FROM `user` WHERE ((last_name LIKE '%frank%') OR (first_name LIKE '%frank%') OR (CONCAT(first_name,' ', last_name) LIKE '%frank%') OR (CONCAT(last_name,' ', first_name) LIKE '%frank%')) AND (deleted = 0 AND scholar = 0) ORDER BY `date_created` DESC LIMIT 25
什麼是正確的語法使用$選擇對象實現這一目標。