gpt4 book ai didi

php - 避免 CI 查询中的反引号

转载 作者:行者123 更新时间:2023-11-29 01:57:19 25 4
gpt4 key购买 nike

我的代码是

public function getbonexpense($yr=null)
{
$this->db->select('year(un_due_date) as year,month(un_due_date) as month,sum(coalesce(bank_amount,0) +amount) as bonsum');
$this->db->from('bon_expense');
$this->db->join('bank_expense','bon_expense.id_bon_exp = bank_expense.bon_exp_id', 'left');
$this->db->where('expense_status',3);
$this->db->group_by('year(un_due_date)');
$this->db->group_by('month(un_due_date)');
if(!empty($yr))$this->db->where('year(un_due_date)',$yr);
$this->db->order_by('month(un_due_date)','desc');
$query = $this->db->get();
if($query->num_rows() != 0)
return $query->result_array();
else
return false;
}

但在运行查询时自动插入代码(`)

SELECT year(un_due_date) as year, month(un_due_date) as month, sum(coalesce(amount, 0)+coalesce(bank_amount, **`0))`** as bonsum
FROM (`crm_bon_expense`)
LEFT JOIN `crm_bank_expense` ON `crm_bon_expense`.`id_bon_exp` = `crm_bank_expense`.`bon_exp_id`
WHERE `expense_status` = 3
AND year(un_due_date) = '2014'
GROUP BY year(un_due_date), month(un_due_date)
ORDER BY month(un_due_date) desc

单个反引号出现在 sum () 函数中。如何避免它?

最佳答案

db -> select 方法中添加 2nd param FALSE,示例代码如下

$this->db->select('year(un_due_date)  as year, 
month(un_due_date) as month,
sum(coalesce(bank_amount,0) +amount) as bonsum', FALSE);


文档:

https://ellislab.com/codeigniter/user-guide/database/active_record.html#select

关于php - 避免 CI 查询中的反引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25279394/

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