我使用这个代码3年没有任何问题。今天服务器突然自动升级到新的mysql版本导致查询错误:
ERROR - 2023-09-06 23:38:40 --> Query error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.`package_id`
WHERE `o`.`status` = 3 AND `o`.`user_id` = '278'' at line 2 - Invalid query: SELECT SUM(p.investment_capital) AS abc
FROM `tbl_product_order o LEFT JOIN tbl_package_master p ON p`.`id =` `o`.`package_id`
WHERE `o`.`status` = 3 AND `o`.`user_id` = '278'
ERROR - 2023-09-06 23:38:40 --> Severity: error --> Exception: Call to a member function row_array() on boolean /home2/aekcom/public_html/zac-work/application/libraries/Common.php 94
以下是我的代码:
function getSelectedOneField($select, $table, $where)
{
$this->CI->db->select($select);
$this->CI->db->from($table);
$where2 = substr($where,6);
$this->CI->db->where($where2);
$query = $this->CI->db->get();
$result = $query->row_array();
if ($result) {
return $result[$select];
}
return null; // Return an appropriate value if no result is found
}
function getTotalInvested($user_id=0)
{
$total_invested= 0;
$total_invested = $this->getSelectedOneField("SUM(p.investment_capital) AS abc", "tbl_product_order o LEFT JOIN tbl_package_master p ON p.id = o.package_id", "WHERE o.status = 3 AND o.user_id = '" . $user_id . "'");
if($total_invested !=''){
$total_invested;
}
return CURRENCY.@number_format($total_invested,2);
}
$data['total_invested'] = $this->common->getTotalInvested($this->session->userdata('WDW_MEMBER_LOGIN_ID'));
如何修复此错误?
我已将SUM(p.investment_capital)
更改为SUM(p.investment_capital) AS abc
1条答案
按热度按时间nx7onnlm1#
您的“join”信息被 Package 在反引号中,因为
from()
函数不打算处理它。尝试在
getSelectedOneField
中单独处理join信息,如下所示:然后这样称呼它: