Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
like image 325
Sizzling Code Avatar asked Aug 24 '14 04:08

Sizzling Code


People also ask

Is CodeIgniter case sensitive?

It's not consistent. Some will search for the name as is and if it doesn't find it it checks to see if a lower-cased version exists and loads that if it does.

What is DB in CodeIgniter?

CodeIgniter has a config file that lets you store your database connection values (username, password, database name, etc.). The config file is located at application/config/database. php. You can also set database connection values for specific environments by placing database.

Is latin1_swedish_ci case sensitive?

The default character set and collation are latin1 and latin1_swedish_ci, so nonbinary string comparisons are case insensitive by default."

Is SQL case sensitive in PHP?

MySQL's queries are case insensitive by default, unless the underlying tables have a case-sensitive collation set.


1 Answers

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))

like image 55
dehrg Avatar answered Sep 30 '22 13:09

dehrg