I am trying to encode the results from SELECT query with prepared statement into JSON output. I have the following code but I can't get it working. Any help would be greatly appreciated.
$query = "SELECT Item.ItemID, Item.ItemName FROM Items"
    $stmt = $db->prepare($query);
    $stmt->execute();
    $stmt->store_result();
    $numrows = $stmt->num_rows;
    $stmt->bind_result($ItemID, $ItemName);
 for ($i=0; $i <$numrows; $i++) {
    $stmt->fetch();
$JSONArray = ["ItemID" => $ItemID,
             "ItemName" => $ItemName
             ]
echo json_encode($JSONArray);
}
 
     
     
     
    