今天博主用原生寫查詢的時候發現,查詢出來的居然不是我數據表里的數據,而是一個對象
object(mysqli_result)#2 (5) {
["current_field"]=>
int(0)
["field_count"]=>
int(8)
["lengths"]=>
NULL
["num_rows"]=>
int(6)
["type"]=>
int(0)
}
問了一波度娘才發現,原來這是正常的返回,框架的db庫都是經過封裝的,在返回的時候已經將結果集轉換了一波才返回的
但是問題是怎么才能把他轉成數組呢,結果集咱也看不懂也不會用啊,於是乎博主又問了一波度娘
最后找到的答案:附上代碼
require('./db.php'); $sql = "select * from wx_menu_bar"; //頂級菜單欄 $menu_bar = $db->query($sql); $result = array(); if($menu_bar) { //轉化為數組 while($value = $menu_bar->fetch_array()) { if(empty($result)){ $result = $value; }else{ $result[] = $value; } } } echo json_encode($result,JSON_UNESCAPED_UNICODE);die;
