Kohana,如何获得$ query-> execute()的结果

时间:2011-07-29 07:27:10

标签: php mysql kohana

    $query = DB::query(Database::SELECT, "select * from users where username like :username") ;
    $query->param(':username', $username) ;
    $query->parameters(array(
        ':username' => '%'. $username. '%'
    )) ;

    $result = $query->execute()->as_array() ;

    if ($result->count() > 0)
    {
        return $result ;
    }
    else
    {
        return null ;
    }

ErrorException [致命错误]:在非对象上调用成员函数count()

如何获取查询结果?任何人帮助..thx ..

1 个答案:

答案 0 :(得分:2)

如果$result = $query->execute()->as_array() ;返回数组,则if语句应为

if (count($result) > 0)
{
    return $result ;
}
else
{
    return null ;
}