Php Codeigniter SQL查询不工作。它的返回是错误的。但如果我们直接在数据库中运行相同的查询,它将返回结果
Codeigniter SQL查询不工作。它的返回是错误的。但是,如果我们将同一个查询直接运行到数据库中,它将返回结果。您没有正确地使用->db->where。示例中正确的codeigniter方式是:Php Codeigniter SQL查询不工作。它的返回是错误的。但如果我们直接在数据库中运行相同的查询,它将返回结果,php,codeigniter,Php,Codeigniter,Codeigniter SQL查询不工作。它的返回是错误的。但是,如果我们将同一个查询直接运行到数据库中,它将返回结果。您没有正确地使用->db->where。示例中正确的codeigniter方式是: $this->db->select('sum(commission_amount) as myamount'); $this->db->from('forex_commissions'); $this->db->where('createdDate
$this->db->select('sum(commission_amount) as myamount');
$this->db->from('forex_commissions');
$this->db->where('createdDate_sql = `2020-02-16` and userRef = `MXkIP8z0vs5J`');
$result = $this->db->get();
使用此语法还会自动转义所有值,从而生成更安全的查询。看
注意:您还可以使用:echo$this->db->last\u query回显最新执行的查询 值应该用单引号或双引号括起来,而不是反引号。但是我也尝试使用单引号和双引号-$this->db->error?
$this->db->select('sum(commission_amount) as myamount');
$this->db->from('forex_commissions');
$this->db->where('createdDate_sql', '2020-02-16');
$this->db->where('userRef', 'MXkIP8z0vs5J');
$result = $this->db->get();