在非对象kohana php 5.4上调用成员函数as_array()

时间:2017-09-13 07:50:09

标签: php kohana

我收到此错误ErrorException [致命错误]:在非对象上调用成员函数as_array()

这是我的代码使用kohana php

$query = 'SELECT * from siteinfo' .( ' WHERE id = \'' . 1 . '\'' );
    $result = Db::query( 'SELECT', $query )->execute(  )->as_array(  );
 //$result = Db::query( 'SELECT', "SELECT * from siteinfo" )->execute(  )->as_array(  );
 //print_r($result);die();

1 个答案:

答案 0 :(得分:0)

正确用法是:

$result = DB::query( Database::SELECT, $query )->execute(  )->as_array(  );

BTW:您应该使用查询构建器(自动参数转义)

$result = DB::select()->from('siteinfo')->where('id','=', 1)->execute()->as_array();

或参数化查询:

$query = 'SELECT * from siteinfo  WHERE id = :id' ;
$result = DB::query( Database::SELECT, $query )->execute(Array(':id'=> 1))->as_array(  );