Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql, case sensitive compare through codeigniter

I wanted to write following query through codeigniter's db helper class, guide me plz

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

I tried

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

but it produces

SELECT * FROM table WHERE column like '%binary abc%'
like image 977
makki Avatar asked Jul 12 '26 21:07

makki


1 Answers

It is not supported directly through the like() helper, but you can do this:

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

An alternative method is:

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

Notice I am using method chaining, it's a little quicker and to me is neater.

like image 125
Phil Sturgeon Avatar answered Jul 14 '26 13:07

Phil Sturgeon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!