I'm trying to get an entire table from mysqli and return it JSON encoded like this:
$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 ""
But when I apply json_encode
on the entire array, it returns nothing.