<?php
include '../config/db.php';

if (isset($_GET['query'])) {
    $query = htmlspecialchars($_GET['query']);

    try {
        $stmt = $pdo->prepare("SELECT drug_name FROM drugs WHERE drug_name LIKE ? LIMIT 10");
        $stmt->execute(['%' . $query . '%']);
        $results = $stmt->fetchAll(PDO::FETCH_ASSOC);

        echo json_encode($results);
    } catch (PDOException $e) {
        echo json_encode([]);
    }
} else {
    echo json_encode([]);
}
