开发者

Kohana V3 return query result as object

开发者 https://www.devze.com 2022-12-25 13:19 出处:网络
In Kohana V3 is it possible to return result set as an array() or any method exists? For example: $user 开发者_开发技巧= DB::select(\'*\')->from(\"users\")->where(\'username\', \'=\', $usernam

In Kohana V3 is it possible to return result set as an array() or any method exists?

For example:

$user 开发者_开发技巧= DB::select('*')->from("users")->where('username', '=', $username);

If method is there,then it is possible to get password like

echo $user->password;

Is it possible without ORM? Please suggest.


I think the following would give you all results:

$user = DB::select('*')->from("users")->where('username', '=', $username)->as_object()->execute();

Whereas the following here, would give you the first item:

$user = DB::select('*')->from("users")->where('username', '=', $username)->as_object()->execute()->current();

Try: KO3 Database Wiki


You just need to add a ->current() to the end of your query:

$user = DB::select('*')->from("users")->where('username', '=', $username)->execute()->current();
0

精彩评论

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