Logo Questions Linux Laravel Mysql Ubuntu Git Menu

Escape the order by query in codeigniter

Here is the SQL query run :

SELECT * FROM (`news`) WHERE `country` IS NULL AND `region` IS NULL ORDER BY IFNULL(update_date, `create_date)` DESC

And you may notice that the create_date has some formatting error, I would like to disable the escape but even I add false after the order_by function it has no effect. How to fix it? Thanks a lot

 $this->db->order_by('IFNULL(update_date,create_date)', 'DESC', false);
 $query = $this->db->get();
 return $query->result_array();
like image 724
user782104 Avatar asked Jan 09 '23 21:01


1 Answers

Use below code:

$this->db->_protect_identifiers = FALSE;

$this->db->order_by('IFNULL(update_date,create_date)', 'DESC', false);

$this->db->_protect_identifiers = TRUE;

like image 173
CodeWithCoffee Avatar answered Jan 11 '23 20:01