query($sql); // Fetch data $data = []; if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { $data[] = $row; } } // Close connection $conn->close(); // Return JSON output header('Content-Type: application/json'); echo json_encode($data, JSON_PRETTY_PRINT); ?>