Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Codeigniter SQL查询不工作。它的返回是错误的。但如果我们直接在数据库中运行相同的查询,它将返回结果_Php_Codeigniter - Fatal编程技术网

Php Codeigniter SQL查询不工作。它的返回是错误的。但如果我们直接在数据库中运行相同的查询,它将返回结果

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

Codeigniter SQL查询不工作。它的返回是错误的。但是,如果我们将同一个查询直接运行到数据库中,它将返回结果。

您没有正确地使用->db->where。示例中正确的codeigniter方式是:

  $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();