<?php
require_once "db.php";
header("Content-Type: application/json; charset=UTF-8");

$sql = "SELECT emp_id, emp_name FROM employee ORDER BY emp_name ASC";
$result = $conn->query($sql);

if (!$result) {
    echo json_encode([
        "success" => false,
        "error" => "Query failed: " . $conn->error
    ]);
    exit();
}

$data = [];
while ($row = $result->fetch_assoc()) {
    $data[] = [
        "emp_id" => intval($row["emp_id"]),
        "emp_name" => $row["emp_name"]
    ];
}

echo json_encode([
    "success" => true,
    "data" => $data
]);