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

function dropCol($db, $table, $col) {
    $res = $db->query("SHOW COLUMNS FROM `$table` LIKE '$col'");
    if ($res && $res->num_rows > 0) {
        $db->query("ALTER TABLE `$table` DROP COLUMN `$col`");
    }
}

$cols = [
    'tanggal_daftar', 'periode_masuk', 'keterangan_keluar', 'dosen_pa_id'
];

foreach ($cols as $col) {
    dropCol($db, 'mahasiswa', $col);
}

dropCol($db, 'peserta_kelas', 'krs_id');
$db->query("DROP TABLE IF EXISTS krs");

echo "Cleanup done.\n";
