我正在尝试从mysqli获取整个表并返回JSON编码,如下所示:
$result = $db->query('select * from categories');
$categories = array();
while ($row = $result->fetch_object()) {
// echo json_encode($row); // Returns the row in JSON.
$categories[] = array('ID' => $row->ID, 'name' => $row->name);
}
echo count($categories); // Returns 28, the amount of categories on the DB
echo json_encode($categories); // returns ""
但是当我在整个数组上应用json_encode
时,它什么都不返回。