php - Codeigniter SQL 查询不起作用。它的回报是假的。但是如果我们直接在数据库中运行相同的查询,它会返回结果
问题描述
$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();
Codeigniter SQL 查询不起作用。它的回报是假的。但是如果我们直接在数据库中运行相同的查询,它会返回结果。
解决方案
你没有->db->where()
正确使用。您示例的正确代码点火器方式是:
$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();
使用此语法还会自动转义所有值,从而产生更安全的查询。看这里
注意:您还可以回显您执行的最新查询:echo $this->db->last_query();
推荐阅读
- ios - WidgetKit 中似乎忽略了时间线重新加载策略
- linux - 是否有直接从 linux 终端将 ASCII 文件的内容转换为普通文本的命令?
- angular - Chart JS, ng2-Charts - 如何使饼图右侧的标签而不是顶部?
- tensorflow2.0 - 没有为具有随机数据和适当模型构建的任何变量提供梯度
- python-3.x - 我的 ARIMA 模型的多个输入功能
- git - Git 存储库都是链接的
- flutter - 小部件状态不会在 iOS 上更新
- user-interface - SwiftUI - 缩放按钮和可点击区域
- list - 如何在matlab中显示用户对话框时取消焦点?
- python - 如何使用 pandas 解析复杂的 JSON 文件格式?