Codeigniter致命错误在布尔值上调用成员函数result()

时间:2016-06-28 10:40:18

标签: php mysql sql codeigniter

我遇到了query的问题,导致以下错误

PHP Fatal error:  Call to a member function result() on boolean on line 200

我对其他queries没有任何问题,但在此问题上,我必须在query内执行query,具体如下:

$this->load->helper('date');
$datestring = "%Y-%m-%d";
$time = strtotime('yesterday');
$date= mdate($datestring, $time);

$db = $this->load->database('macs', TRUE);

$query = $db->query("SELECT TEMP1.USER AS PACKER, Count(TEMP1.[ORDER]) AS ORDERS FROM (SELECT AUDIT.USER, AUDIT.[ORDER] FROM AUDIT WHERE AUDIT.DATE > '$date' AND (AUDIT.TYPE='I11' Or AUDIT.TYPE =' 11') GROUP BY AUDIT.DATE, AUDIT.TYPE, AUDIT.USER, AUDIT.[ORDER]) AS TEMP1 GROUP BY TEMP1.USER ORDER BY Count(TEMP1.[ORDER]) DESC");

return $query->result();
$macsdb->close();

这在访问中正常工作(以上是访问查询的转换)。当引用query的任何内容被移除时,USER开始工作(但不正确),甚至在USER被其他字段(例如公司)替换时也能正常工作。是什么导致此查询无法使用USER

1 个答案:

答案 0 :(得分:0)

我在没有返回的情况下运行查询并出现语法错误。问题是USER必须变为[USER]