我不确定这是与Opencart相关的问题还是只是PHP / MySQL问题。
在admin/model/report/test_module.php
中,这就是我所拥有的:
class ModelReportTestModule extends Model {
public function getData($data = array()) {
$sql = "SELECT * FROM ". DB_PREFIX . "test_module";
if (!empty($data['filter_group'])) {
$sql .= " WHERE url = '" . $this->db->escape($data['filter_group']) . "'";
}
if (!empty($data['filter_date_start'])) {
$sql .= " AND date >= '" . $this->db->escape($data['filter_date_start']) . "'";
}
if (!empty($data['filter_date_end'])) {
$sql .= " AND date <= '" . $this->db->escape($data['filter_date_end']) . "'";
}
$result = $this->db->query($sql);
return $result->rows;
}
}
在上面的函数中传递的 $data
包含一个数组,如下所示:
Array ( [filter_date_start] => 2013-07-10 [filter_date_end] => 2013-07-12 [filter_group] => http://localhost/oc-1.5.5.1/index.php?route=product/category&path=18 )
在数据库中,值以这种格式存储:
date(datetime): 2013-07-11 09:41:17
url(text): http://localhost/oc-1.5.5.1/index.php?route=product/category&path=18
如果我直接在phpMyAdmin的SQL控制台中运行下面的查询,它可以正常工作并给我正确的行:
SELECT * FROM `oc_test_module` WHERE
`url` = 'http://localhost/oc-1.5.5.1/index.php?route=product/category&path=18' and
`date_time` >= '2013-07-10' and
`date_time` <= '2013-07-12';
然而,当我在报表模型中尝试它时,它无法检索任何内容,这与SQL查询几乎完全相同。我花了几个小时但却无法弄清楚我错过了什么。也许是一些我无法看到的微不足道的东西。
答案 0 :(得分:2)
解决此问题的最简单方法是在
之前的行上var_dump($sql);
$result = $this->db->query($sql);
然后在PHPMyAdmin中调试它。它可能是一些微不足道的事情,例如查询中&
为&
。如果不能立即明白导致问题的原因,请在工作和非工作查询之间使用差异工具
答案 1 :(得分:0)
我有同样的问题,花了一个小时后我发现我用不同的数据库连接。我的意思是我的opencart连接到数据库&#39; DB1&#39;但我运行sql到数据库&#39; DB2&#39;在phpmyadmin。这就是为什么我没有得到任何结果但没有显示任何错误。
也许您使用不同的数据库对其进行测试,以便显示不同的结果。