<?php
$conn = new mysqli('localhost', 'root', '', 'siakad');
if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); }

$sql = "CREATE TABLE IF NOT EXISTS ref_wilayah (
    id_wilayah VARCHAR(8) NOT NULL,
    nama_wilayah VARCHAR(255) NOT NULL,
    id_induk_wilayah VARCHAR(8) NULL,
    PRIMARY KEY (id_wilayah),
    INDEX (id_induk_wilayah),
    INDEX (nama_wilayah)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;";

if ($conn->query($sql) === TRUE) {
    echo "Table ref_wilayah created successfully.";
} else {
    echo "Error creating table: " . $conn->error;
}
$conn->close();
