2010-03-29 59 views
0

我想通过CodeIgniter的分贝辅助类写下面的查询比较,引导我PLZmysql的,区分大小写通过笨

SELECT * FROM table where column like binary "abc"; 

我试图

$this->db->select("*"); 
$this->db->from("table"); 
$this->db->like("column","binary abc"); 
$this->db->get(); 

,但它产生的

SELECT * FROM table WHERE column like '%binary abc%' 

回答

11

它不是通过像()辅助直接支持,但你可以这样做:

$result = $this->db 
    ->where('column like binary "abc"', NULL, FALSE) 
    ->get('table') 
    ->result(); 

另一种方法是:

$result = $this->db 
    ->where('LOWER(column)', strtolower($foo), FALSE) 
    ->get('table') 
    ->result(); 

注意我正在使用方法链,它速度更快,对我来说更整洁。

+0

它只是小写的字段值和与之相匹配的小写用户输入,它还更新实际数据的敏感性,意思是,如果用户输入“ABCD”,它将匹配与abcD在数据库中是错误的。除了更改列归类之外,是否还有其他方法可以处理区分大小写的记录。 – Adnan 2015-10-26 08:48:41

0

用途:

$ this-> db-> where('column like binary“abc”');
$ result = $ this-> db-> get('table');

问候,
佩德罗

0

我用的是和它的工作

$this->db->from("table_name"); 
$this->db->where('column_name like binary', $value);