48 lines
1.4 KiB
PHP
48 lines
1.4 KiB
PHP
<?php
|
|
$host = getenv('DB_HOST') ?: 'mysql';
|
|
$port = (int)(getenv('DB_PORT') ?: 3306);
|
|
$user = 'root';
|
|
$pass = getenv('MYSQL_ROOT_PASSWORD') ?: 'root_password';
|
|
|
|
echo "Menghubungkan ke database...<br>\n";
|
|
$conn = new mysqli($host, $user, $pass, '', $port);
|
|
|
|
if ($conn->connect_error) {
|
|
die("Koneksi gagal: " . $conn->connect_error);
|
|
}
|
|
echo "Koneksi berhasil!<br>\n";
|
|
|
|
$conn->set_charset('utf8mb4');
|
|
|
|
function executeSqlFile($conn, $filePath) {
|
|
if (!file_exists($filePath)) {
|
|
echo "File tidak ditemukan: $filePath<br>\n";
|
|
return;
|
|
}
|
|
|
|
echo "Mengeksekusi $filePath...<br>\n";
|
|
$sql = file_get_contents($filePath);
|
|
|
|
// Execute multi query
|
|
if ($conn->multi_query($sql)) {
|
|
do {
|
|
// Store first result set
|
|
if ($result = $conn->store_result()) {
|
|
$result->free();
|
|
}
|
|
// print divider
|
|
} while ($conn->more_results() && $conn->next_result());
|
|
echo "✅ Sukses mengeksekusi $filePath<br>\n";
|
|
} else {
|
|
echo "❌ Gagal mengeksekusi $filePath: " . $conn->error . "<br>\n";
|
|
}
|
|
}
|
|
|
|
// Urutan eksekusi file SQL
|
|
executeSqlFile($conn, __DIR__ . '/01/database_01.sql');
|
|
executeSqlFile($conn, __DIR__ . '/02/database_02.sql');
|
|
executeSqlFile($conn, __DIR__ . '/05/webgis_uas_FIXED_v2/webgis_uas_FIXED/database_LENGKAP.sql');
|
|
|
|
echo "<br><b>SEMUA DATABASE BERHASIL DIBUAT DAN DI-MIGRASI!</b> Anda bisa menghapus file setup_db.php ini nanti.";
|
|
?>
|