【发布时间】:2013-05-11 01:39:43
【问题描述】:
当我尝试使用 DB::select 而不是 ORM 时,就会发生这种情况。 查询作为对象返回,但出现错误。
代码:
$bd_userdata -> offset($pagination -> offset) -> limit($pagination -> items_per_page) -> find_all() -> as_array();
错误:
ErrorException [致命错误]:调用未定义的方法 Database_MySQL_Result::offset()
这是否意味着我必须先计算行数,然后才能将它们发送到分页中的偏移量?
当我尝试$query->count_all() 时,我收到错误消息:
未定义属性:Database_Query_Builder_Select::$count_all
我尝试了count($query),但得到了:
没有使用表 [SELECT * LIMIT 4 OFFSET 0]
解决办法如下:
$results = DB::select('*')
->from('users')
->where('id', '=', 1)
->limit($pagination->items_per_page)
->offset($pagination->offset)->execute();
还有一个计数器:
$count = $results->count_all();我以前也这样做过,反之亦然。这就是为什么它不起作用。
【问题讨论】:
-
$bd_userdata是什么类型? -
这很简单:DB::select()->from('users')->where('username', '=', 'test')->execute();