【问题标题】:Escape the order by query in codeigniter在codeigniter中通过查询转义订单
【发布时间】:2015-04-14 01:03:54
【问题描述】:

这是运行的 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->order_by('IFNULL(update_date,create_date)', 'DESC', false);我想这可能是因为你有 false in order by。
  • 感谢您的回复。无论有无 false 都返回相同的结果

标签: php mysql sql codeigniter


【解决方案1】:

使用下面的代码:

$this->db->_protect_identifiers = FALSE;

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

$this->db->_protect_identifiers = TRUE;

【讨论】:

    【解决方案2】:

    将此行添加到您的数据库选择方法的顶部。

    $this->db->_protect_identifiers = FALSE;

    【讨论】:

      【解决方案3】:

      只是为了更新,尝试使用乘法进行 sql 选择以在 C.I. 上工作。 3.10

      $this->db->order_by("results.result * 1", 'ASC', FALSE);
      

      只需将 , FALSE 添加到 order_by 即可解决,因为 $this->db->_protect_identifiers 在 C.I. 上触发了一个错误。 3.10

      【讨论】:

        猜你喜欢
        • 2012-06-13
        • 2016-02-28
        • 1970-01-01
        • 2012-09-01
        • 2011-05-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多