query($sql); $data = []; while ($row = $result->fetch_assoc()) { $data[] = $row; } echo json_encode($data); $conn->close(); ?>