<?php
// **Koneksi ke database**
$conn = mysqli_connect("localhost", "root", "", "spk");

// **Pastikan koneksi berhasil**
if (!$conn) {
    die("Koneksi gagal: " . mysqli_connect_error());
}

// **Fungsi query hanya dideklarasikan sekali**
if (!function_exists("query")) {
    function query($query) {
        global $conn;
        $result = mysqli_query($conn, $query);
        $rows = [];
        while ($row = mysqli_fetch_assoc($result)) {
            $rows[] = $row;
        }
        return $rows;
    }
}
?>
