1
在Kohana V3中,是否可以返回结果集作为数组()或存在任何方法?Kohana V3将查询结果作为对象返回
例如:
$user = DB::select('*')->from("users")->where('username', '=', $username);
如果方法是存在的,那么就可以得到像
echo $user->password;
密码是否有可能不ORM?请建议。
在Kohana V3中,是否可以返回结果集作为数组()或存在任何方法?Kohana V3将查询结果作为对象返回
例如:
$user = DB::select('*')->from("users")->where('username', '=', $username);
如果方法是存在的,那么就可以得到像
echo $user->password;
密码是否有可能不ORM?请建议。
我认为有以下会给你所有的结果:
$user = DB::select('*')->from("users")->where('username', '=', $username)->as_object()->execute();
而下面在这里,会给你的第一个项目:
$user = DB::select('*')->from("users")->where('username', '=', $username)->as_object()->execute()->current();
你只需要在您的查询结尾添加->current()
:
$user = DB::select('*')->from("users")->where('username', '=', $username)->execute()->current();
嗨克雷格,感谢您的答复。但不幸的是,当试图访问echo $ user-> password时; 引发错误ErrorException [注意]:未定义的属性:Database_MySQL_Result :: $密码 – Asif 2010-03-30 05:28:58
您使用了哪种方法?对迟交的歉意表示抱歉。 – Craig 2010-04-03 10:34:52
嗨克雷格,我尝试了上面给出的语法,并试图获取$ user->密码,那个时候出现这个错误。 – Asif 2010-04-06 09:48:52