简体   繁体   English

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

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

    $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 [ Fatal Error ]: Call to a member function count() on a non-object ErrorException [致命错误]:在非对象上调用成员函数count()

how to get the result of query?anybody help ..thx.. 如何获得查询结果?有人帮助..thx ..

If $result = $query->execute()->as_array() ; 如果$result = $query->execute()->as_array() ; returns an array, your if statement should be 返回一个数组,您的if语句应为

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 显示$ query-> result(); - Display $query->result(); $ query-> get_result()是获取结果的正确方法吗? - Is $query->get_result() the Correct Way to Get Results? 如何在不使用foreach循环的情况下通过在Codeigniter中使用$ query-> result()从数据库获取数据? - How to get data from database by using $query->result() in codeigniter without foreach loop? $ query-> row()和$ query-> result()的最简单解释 - simplest explanation of $query->row() and $query->result() 如何在Codeigniter上使用$ query-> row获取类对象 - How to get class object with $query->row on Codeigniter Codeigniter $ query-> result()循环到关联数组 - Codeigniter $query->result() loop to associative array Codeigniter $ query-> result()返回奇怪的结果 - Codeigniter $query->result() returns strange results 如何从Kohana 3.2的查询结果中获取索引数组? - How can I get an indexed array from query result in Kohana 3.2? 合并$ query-> result()和数组codeigniter的结果 - Merging result from $query->result() and an array codeigniter Codeigniter $ query-> row_array()SQL $ query-> result_array() - Codeigniter $query->row_array() SQL $query->result_array()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM