public function get_details($id)
{
//my query in pdo form getting my records
$query = $this->db->query("SELECT * FROM users WHERE idno='". $id ."'");
//check if query is successfull
if($query)
{
$query->result_array();//get the result through array form
print_r($query);//prints the array
}
// end if
}//end function
上面代码的结果是这样的:
CI_DB_pdo_result Object ( [num_rows] => 1 [conn_id] => PDO Object ( ) [result_id] => PDOStatement Object ( [queryString] => SELECT * FROM users WHERE idno='888812' ) [result_array] => Array ( [0] => Array ( [idno] => 888812 [lname] => smith [fname] => john [username] => john [password] => password [usertype] => a [status] => a ) ) [result_object] => Array ( ) [custom_result_object] => Array ( ) [current_row] => 0 [row_data] => )
通常result_array()
函数的结果只是正在执行的游标/结果查询的数组,现在我有一个问题,如何从这种带有许多不同数据的 result_array() 返回值。
通常结果现在会是Array([id] => 888812, [lname] => smith, [fname] => john, [username] => john, [password] => password.....)
这样,为什么我会得到上面显示的这种数组?以及我将如何访问我的数据?
每当我访问我的数据$query['result_array']
或$query['idno']
我收到此错误
时Fatal error: Cannot use object of type CI_DB_pdo_result as array in C:/.........