开发者

Kohana database select, list of fields

开发者 https://www.devze.com 2023-04-09 13:41 出处:网络
In Kohana if I want to select fields \'id\', and \'username\' I do it this way: $record = DB::select(\'id\', \'username\')

In Kohana if I want to select fields 'id', and 'username' I do it this way:

$record = DB::select('id', 'username')
                    ->from('users')
                    ->where('id', '=', 1)
                    ->as_object()
                    ->execute();

But how to do it if the list of fields I need to select is in开发者_Go百科 an array, like this:

$fields = array('id', 'username');

How to use DB::select in this situation?


You are looking for DB::select_array().

You can also use $record = call_user_func_array('DB::select', $fields) and then continue building the query; it might be ugly but it also works :)

0

精彩评论

暂无评论...
验证码 换一张
取 消