【发布时间】:2018-05-11 07:30:41
【问题描述】:
Codeigniter 活动记录查询给了我错误。如何将 SOUNDS LIKE 放入 where 子句。
function _search($type, $q, $qes, $sort = null, $start = 0) {
$type = strtolower($type);
$q = strtolower($q);
$this->db->select("*");
$this->db->from("books");
$this->db->where("SOUNDEX(name) IN({$q})");
foreach($qes as $k){
$this->db->or_where("name SOUNDS LIKE '$k'");
}
foreach($qes as $k){
$this->db->or_where("name LIKE '%$k%'");
}
$this->db->where("status", 1);
if ($type != NULL) {
$this->db->where("LOWER(type)", $type);
}
//$this->db->like("LOWER(name)", $q);
$this->db->limit(BWK_MAX_BOOK_SIZE, $start);
switch ($sort) {
case 1:
break;
case 2:
$this->db->order_by("sellingPrice", "ASC");
break;
case 3:
$this->db->order_by("sellingPrice", "DESC");
break;
case 4:
$this->db->order_by("created", "DESC");
break;
}
当我回显查询时,这给了我查询。我正在搜索 technologi 我需要获得技术技术等。
SELECT * FROM `books` WHERE SOUNDEX(name) IN('t254') OR `name` `SOUNDS` LIKE 'technolog' OR `name` LIKE '%technologi%' AND `status` = 1 AND LOWER(type) = 'school' LIMIT 50
遇到错误
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '`SOUNDS` LIKE 'technolog' OR `name` LIKE '%technolog%' AND `status` = 1 AND LOWE' at line 4
一切正常,但是当我输入 SOUNDS LIKE 时,它给了我错误。
【问题讨论】:
-
从 SOUNDS 中删除反引号
-
@Bart 我如何删除。我没有放反引号它会自动使用。
标签: mysql sql codeigniter activerecord