feat: add import_db.php to auto setup db in nixpacks
This commit is contained in:
@@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
// Script untuk otomatis setup database jika menggunakan Nixpacks
|
||||||
|
error_reporting(E_ALL);
|
||||||
|
ini_set('display_errors', 1);
|
||||||
|
|
||||||
|
echo "<h1>Setup Database Automatis</h1>";
|
||||||
|
|
||||||
|
$host = getenv("DB_HOST") ?: "localhost";
|
||||||
|
$user = getenv("DB_USER") ?: "root";
|
||||||
|
$pass = getenv("DB_PASS") ?: "fira123";
|
||||||
|
|
||||||
|
// Koneksi tanpa nama database dulu untuk bikin database-nya
|
||||||
|
$conn = new mysqli($host, $user, $pass);
|
||||||
|
if ($conn->connect_error) {
|
||||||
|
die("Koneksi gagal: " . $conn->connect_error);
|
||||||
|
}
|
||||||
|
echo "<p>✅ Terhubung ke server MySQL ($host)</p>";
|
||||||
|
|
||||||
|
// 1. Setup WEBGIS
|
||||||
|
echo "<h2>1. Setup Database WEBGIS</h2>";
|
||||||
|
$sql_webgis = file_get_contents(__DIR__ . '/WEBGIS/01/api/setup_webgis.sql');
|
||||||
|
if ($conn->multi_query($sql_webgis)) {
|
||||||
|
do {
|
||||||
|
// clear results
|
||||||
|
if ($res = $conn->store_result()) {
|
||||||
|
$res->free();
|
||||||
|
}
|
||||||
|
} while ($conn->more_results() && $conn->next_result());
|
||||||
|
echo "<p>✅ Import WEBGIS berhasil!</p>";
|
||||||
|
} else {
|
||||||
|
echo "<p>❌ Error import WEBGIS: " . $conn->error . "</p>";
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Setup KEMISKINAN_IBADAH
|
||||||
|
echo "<h2>2. Setup Database Kemiskinan & Ibadah</h2>";
|
||||||
|
$conn->query("CREATE DATABASE IF NOT EXISTS kemiskinan_ibadah CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;");
|
||||||
|
$conn->select_db("kemiskinan_ibadah");
|
||||||
|
|
||||||
|
$sql_webtugas = file_get_contents(__DIR__ . '/webtugas/01/api/setup_webtugas.sql');
|
||||||
|
if ($conn->multi_query($sql_webtugas)) {
|
||||||
|
do {
|
||||||
|
// clear results
|
||||||
|
if ($res = $conn->store_result()) {
|
||||||
|
$res->free();
|
||||||
|
}
|
||||||
|
} while ($conn->more_results() && $conn->next_result());
|
||||||
|
echo "<p>✅ Import Kemiskinan & Ibadah berhasil!</p>";
|
||||||
|
} else {
|
||||||
|
echo "<p>❌ Error import Kemiskinan & Ibadah: " . $conn->error . "</p>";
|
||||||
|
}
|
||||||
|
|
||||||
|
$conn->close();
|
||||||
|
echo "<h2>🎉 Setup Selesai!</h2>";
|
||||||
|
echo "<p><a href='/'>Kembali ke Home</a></p>";
|
||||||
|
?>
|
||||||
Reference in New Issue
Block a user