我有一个功能:
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。
我的代码有什么问题? 以前我谢谢你...
最佳答案
感谢您的回答,我发现了我的错误,我应该使用数据表查询生成器:($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();
关于php - 使用 $this->db->select(); 时如何在 codeigniter 中禁用反引号;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48743570/