开发者

Kohana, how to get the result of $query->execute()

开发者 https://www.devze.com 2023-03-23 22:36 出处:网络
$query = DB::query(Database::SELECT, \"select * from users where username like :username\") ; $query->param(\':username\', $username) ;
    $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 [ Fata开发者_StackOverflow中文版l Error ]: Call to a member function count() on a non-object

how to get the result of query?anybody help ..thx..


If $result = $query->execute()->as_array() ; returns an array, your if statement should be

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

精彩评论

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

关注公众号