【问题标题】:how to disable backticks in codeigniter when using $this->db->select();使用 $this->db->select() 时如何在 codeigniter 中禁用反引号;
【发布时间】:2018-02-12 09:52:30
【问题描述】:

我有一个功能:

  function datatables ()
  {
    $this->db->select('
      (CASE 
        WHEN L_Type_Name="Khusus" 
        THEN CONCAT("<i id=",L_Type_ID," class=\"formUpdate\" title=\"Ubah\"></i> <i id=",L_Type_ID," class=\"formDelete\" title=\"Hapus\"></i>")
      END) Option');
    $this->db->from('leave_type');
    return $this->datatables->generate();
  }

执行时,错误:

<h1>A Database Error Occurred</h1>
    <p>Error Number: 1064</p><p>You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'L_Type_ID`, " class=\"formDelete\" title=\"Hapus\"></i>")
      END) Option
FRO' at line 3</p><p>SELECT (CASE 
        WHEN L_Type_Name="Khusus" 
        THEN CONCAT("<i id=", `L_Type_ID`, " class=\"formUpdate\" title=\"Ubah\"></i> <i `id="`, `L_Type_ID`, " class=\"formDelete\" title=\"Hapus\"></i>")
      END) Option
FROM `leave_type`</p><p>Filename: C:/XAMPP/htdocs/sicuti/system/database/DB_driver.php</p><p>Line Number: 691</p>

我认为发生错误是因为这里有一个引用/反引号:

<i `id="`, `L_Type_ID`, "

然后我添加了 FALSE 参数以在此处删除引号/反引号:

$this->db->select('',FALSE); 

这里:

$this->db->from('',false);

但是,出现另一个错误,表明没有使用表:

<h1>A Database Error Occurred</h1>
    <p>Error Number: 1096</p><p>No tables used</p><p>SELECT *</p><p>Filename: C:/XAMPP/htdocs/sicuti/system/database/DB_driver.php</p><p>Line Number: 691</p>

我在一个中删除了 FALSE 参数 $this->db->select() 和 $this->db->from(),同样的错误 1096。

我的代码有什么问题? 之前谢谢你...

https://pastebin.com/k6Mbfrcx

【问题讨论】:

  • 对于自定义查询,您可以使用$this-&gt;db-&gt;query( .... )

标签: php mysql sql codeigniter datatables


【解决方案1】:

感谢您的回答,我发现了我的错误,我应该使用数据表查询生成器:($this->datatables)而不是 CI:($this->db)。

$this->datatables->select('
     (CASE
       WHEN L_Type_Name="Khusus"
       THEN CONCAT("<i id=",L_Type_ID," class=\"formUpdate\" title=\"Ubah\"></i> <i id=",L_Type_ID," class=\"formDelete\" title=\"Hapus\"></i>")
     END) Option', false);
$this->datatables->from('leave_type');
return $this->datatables->generate();

CODE IN PASTEBIN

【讨论】:

    【解决方案2】:

    我认为你在fromselect中都使用了false,你只需要在select()中使用false

    试试这个:

    $this->datatables->select('
            (CASE 
                WHEN leave_type.L_Type_Name="Khusus" 
                THEN CONCAT("<i id=",leave_type.L_Type_ID," class=\"formUpdate\" title=\"Ubah\"></i> <i id=",leave_type.L_Type_ID," class=\"formDelete\" title=\"Hapus\"></i>")
            END) Option', false);
    $this->datatables->from('leave_type');
    return $this->datatables->generate();
    

    【讨论】:

    • 谢谢,但我已经这样做了,但仍然出现这样的错误:code

      发生数据库错误

      错误编号:1096

      未使用表

      SELECT *

      文件名:C:/XAMPP/htdocs/sicuti/system/database/DB_driver.php

      行号: 691

      code
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-14
    • 2013-05-31
    • 2016-12-29
    • 2023-03-27
    • 1970-01-01
    • 2011-10-20
    相关资源
    最近更新 更多