Simone
Simone

Reputation: 656

how do i ignore the backticks in codeigniter when using active records? i need to order by cases

how do i ignore the backticks in codeigniter when using active records? i need to order by cases

case when roll_number is null then 1 else 0 end,

which code igniter makes it as

ORDER BY `case` when roll_number is null then 1 else 0 end

which gives me an error. Please help

Upvotes: 1

Views: 5018

Answers (3)

Simone
Simone

Reputation: 656

Thanks for your answers...

I figured out that in active records when using $this->db->order_by() you can't skip the backticks.

So ended up using $this->db->query($sql); where I assigned my normal mysql query to the $sql variable

Upvotes: 1

stalin
stalin

Reputation: 3464

This could be a little old, but for someone who is looking for an answers you could add

$this->db->_protect_identifiers=false;

be aware that this will remove all backticks on this query

Upvotes: 13

John Conde
John Conde

Reputation: 219814

From the docs:

$this->db->select() accepts an optional second parameter. If you set it to FALSE, CodeIgniter will not try to protect your field or table names with backticks. This is useful if you need a compound select statement.

Upvotes: 2

Related Questions