gpt4 book ai didi

codeigniter - 代码点火器总是逃避我的 SELECT ... CASE 查询

转载 作者:行者123 更新时间:2023-12-01 12:29:42 24 4
gpt4 key购买 nike

我正在使用 Codeigniter 对我的数据库进行查询。代码如下:

$this->db->select("category.Name,
booking.Comment,
CASE WHEN amount > 0 THEN amount END AS PosAmount,
CASE WHEN amount < 0 THEN amount END AS NegAmount");

但我总是得到一个
You have an error in your SQL syntax ... right syntax to use near
'WHEN amount > 0 THEN amount END AS PosAmount, `CASE` WHEN amount < 0
THEN amount' at line 1

Codeigniter 正在逃避 CASE,但我不知道如何防止这种情况发生。

有任何想法吗?

最佳答案

来自 documentation :

$this->db->select() accepts an optional second parameter. If you set it to FALSE, CodeIgniter will not try to protect your field or table names. This is useful if you need a compound select statement where automatic escaping of fields may break them.



在你的情况下:
$this->db->select("category.Name,
booking.Comment,
CASE WHEN amount > 0 THEN amount END AS PosAmount,
CASE WHEN amount < 0 THEN amount END AS NegAmount", FALSE);

第二个参数也可用于 where 和 join 子句。

关于codeigniter - 代码点火器总是逃避我的 SELECT ... CASE 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35501418/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com