猿问

Codeigniter select_sum 生成错误的查询

我参与了一个Codeigniter 2 项目,在那里我有一个活跃的记录,比如:

$query = $this->db->select_sum('Cardit * GPA', 'sum')
                  ->get('marks_info');

它生成如下查询:

SELECT SUM(`Cardit` * `GPA`) AS `sum` FROM `marks_info`

最近我将我的项目迁移到 Codeigniter 3,但相同的活动记录生成了一些不同的查询,例如:

SELECT SUM(`Cardit *` `GPA`) AS `sum` FROM `marks_info`

这是错误的,它在 SUM 部分包含 * with Cardit ( 'Cardit *' )。

区别:

谁能告诉我,我如何在 CodeIgniter 3 中解决这个问题?


PIPIONE
浏览 261回答 2
2回答

海绵宝宝撒

试试这个,它会给你你预期的输出$query = $this->db->select('sum(Cardit * GPA) sum')->get('marks_info');

慕田峪4524236

避免查询中的反引号。您可以将false分配给protect_identifierslike :$this->db->_protect_identifiers=false;并相应地运行您的查询。
随时随地看视频慕课网APP
我要回答