<?php
$conn = new mysqli("localhost", "root", "", "klinik");
if ($conn->connect_error) die("Koneksi gagal: " . $conn->connect_error);

$term = strtolower($_GET['term'] ?? '');
$stmt = $conn->prepare("SELECT nama FROM data_obat WHERE nama LIKE CONCAT(?, '%') LIMIT 10");
$stmt->bind_param("s", $term);
$stmt->execute();
$result = $stmt->get_result();

$data = [];
while ($row = $result->fetch_assoc()) {
  $data[] = $row['nama'];
}
echo json_encode($data);
?>
