views:

376

answers:

2

Hi,

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.

A: 

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

Craig
Hi Craig, Thanks for reply. But unfortunately when trying to access echo $user->password;throws error ErrorException [ Notice ]: Undefined property: Database_MySQL_Result::$password
Asif
Which method did you use? Apologies for late reply.
Craig
Hi Craig, I tried with the syntax given above and tried to fetch $user->password, that time this error appears.
Asif
Have you tried using the second query I provided? It uses the method current(); and returns a usable object. I was able to echo $user->password; without any issues.
Craig
A: 

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

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