<?php
header('Content-Type: application/json'); // <-- Tell browser this is JSON

include('db.php');

$sql = "SELECT name, from_number FROM Contact ORDER BY id DESC";
$result = $conn->query($sql);

$contacts = [];

if ($result && $result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        $contacts[] = $row;
    }
}

$conn->close();

echo json_encode($contacts, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
