在 codeigniter 中通过查询转义订单
Escape the order by query in codeigniter
这里是 SQL 查询 运行 :
SELECT * FROM (`news`) WHERE `country` IS NULL AND `region` IS NULL ORDER BY IFNULL(update_date, `create_date)` DESC
你可能会注意到 create_date 有一些格式错误,我想禁用转义但即使我在 order_by 函数之后添加 false 它也没有效果。如何解决?非常感谢
$this->db->select('*');
$this->db->from('news');
$this->db->where($data);
$this->db->order_by('IFNULL(update_date,create_date)', 'DESC', false);
$query = $this->db->get();
return $query->result_array();
使用以下代码:
$this->db->_protect_identifiers = 假;
$this->db->order_by('IFNULL(update_date,create_date)', 'DESC', false);
$this->db->_protect_identifiers = TRUE;
将此行添加到您的数据库 select 方法之上。
$this->db->_protect_identifiers = FALSE;
只是为了更新,尝试使 sql select 具有乘法以在 C.I 上工作。 3.10
$this->db->order_by("results.result * 1", 'ASC', FALSE);
只需将 , FALSE 添加到 order_by 即可解决,因为 $this->db->_protect_identifiers 在 C.I 上触发错误。 3.10
这里是 SQL 查询 运行 :
SELECT * FROM (`news`) WHERE `country` IS NULL AND `region` IS NULL ORDER BY IFNULL(update_date, `create_date)` DESC
你可能会注意到 create_date 有一些格式错误,我想禁用转义但即使我在 order_by 函数之后添加 false 它也没有效果。如何解决?非常感谢
$this->db->select('*');
$this->db->from('news');
$this->db->where($data);
$this->db->order_by('IFNULL(update_date,create_date)', 'DESC', false);
$query = $this->db->get();
return $query->result_array();
使用以下代码:
$this->db->_protect_identifiers = 假;
$this->db->order_by('IFNULL(update_date,create_date)', 'DESC', false);
$this->db->_protect_identifiers = TRUE;
将此行添加到您的数据库 select 方法之上。
$this->db->_protect_identifiers = FALSE;
只是为了更新,尝试使 sql select 具有乘法以在 C.I 上工作。 3.10
$this->db->order_by("results.result * 1", 'ASC', FALSE);
只需将 , FALSE 添加到 order_by 即可解决,因为 $this->db->_protect_identifiers 在 C.I 上触发错误。 3.10