简体   繁体   中英

codeigniter $this->db->like is case sensitive

Here is the code.

function get_autoComplete($tbl, $data, $field, $value, $where='',$group_by=false,$limit=''){
    $this->db->select($data);
    $this->db->from($tbl);
    if($where!=''){
        $this->db->where($where);
    }
    $this->db->like($field, $value);
    if($group_by == true){
    $this->db->group_by($field);
    }
    if($limit !='')
    {
        $this->db->limit($limit);
    }
    $query=$this->db->get();
    return $query->result();
}

In the second select statement, it seems as though like($field, $value) is case sensitive. I want it to be insensitive, so I can search without worrying about upper and lower case.

it has something to do with

$this->db->like($field, $value);

There is no case insensitive version of the like function. What you can do is transform both sides of the comparison to lower case, so that you take that out of the equation.

like('LOWER(' .$field. ')', strtolower($value))

Very late to the party!

CodeIgniter 3 has the feature in like() . https://codeigniter.com/user_guide/database/query_builder.html#looking-for-similar-data

Haven't used CI4 yet, so can't be sure there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM