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

时间:2016-06-27 10:38:11

标签: php sql codeigniter advantage-database-server

我遇到了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 TOP 1 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开始工作(但不正确)。可能导致这种情况的原因是什么?

1 个答案:

答案 0 :(得分:2)

MySQL不支持TOP子句

如果你想获得TOP 1记录,你可以使用这样的查询

SELECT * FROM table_name ORDER BY field_name DESC LIMIT 1