38 lines
1.1 KiB
PHP
38 lines
1.1 KiB
PHP
<?php
|
|
require_once __DIR__ . '/config/db.php';
|
|
|
|
echo "<h1>Import Database</h1>";
|
|
|
|
$sqlFile = __DIR__ . '/database/database.sql';
|
|
|
|
if (!file_exists($sqlFile)) {
|
|
die("Error: File database.sql tidak ditemukan di path: " . htmlspecialchars($sqlFile));
|
|
}
|
|
|
|
$sql = file_get_contents($sqlFile);
|
|
|
|
if (empty(trim($sql))) {
|
|
die("Error: File database.sql kosong.");
|
|
}
|
|
|
|
try {
|
|
$pdo = getDB();
|
|
|
|
// Nonaktifkan foreign key checks untuk menghindari error saat drop/create tabel
|
|
$pdo->exec("SET FOREIGN_KEY_CHECKS = 0;");
|
|
|
|
// Eksekusi semua query yang ada di dalam file SQL
|
|
$pdo->exec($sql);
|
|
|
|
// Aktifkan kembali foreign key checks
|
|
$pdo->exec("SET FOREIGN_KEY_CHECKS = 1;");
|
|
|
|
echo "<h3 style='color: green;'>Import Berhasil!</h3>";
|
|
echo "<p>Seluruh struktur tabel dan data dari file database.sql telah berhasil dieksekusi ke database <b>" . htmlspecialchars(DB_NAME) . "</b>.</p>";
|
|
echo "<p><a href='debug.php'>Lihat isi database di sini (debug.php)</a></p>";
|
|
|
|
} catch (PDOException $e) {
|
|
echo "<h3 style='color: red;'>Import Gagal!</h3>";
|
|
echo "<p><b>Error Message:</b> " . htmlspecialchars($e->getMessage()) . "</p>";
|
|
}
|