Kohana数据库选择,字段列表

时间:2022-10-13 12:31:27

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

在Kohana,如果我想选择字段'id'和'username',我会这样做:

$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 an array, like this:

但是如果我需要选择的字段列表在一个数组中,如何做到这一点,如下所示:

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

How to use DB::select in this situation?

在这种情况下如何使用DB :: select?

1 个解决方案

#1


2  

You are looking for DB::select_array().

您正在寻找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 :)

您还可以使用$ record = call_user_func_array('DB :: select',$ fields)然后继续构建查询;它可能很难看但它也有效:)

#1


2  

You are looking for DB::select_array().

您正在寻找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 :)

您还可以使用$ record = call_user_func_array('DB :: select',$ fields)然后继续构建查询;它可能很难看但它也有效:)