New config for docker-compose
This commit is contained in:
+44
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
// FILE INI HANYA UNTUK INISIALISASI DATABASE
|
||||
// HAPUS SETELAH DIPAKAI!
|
||||
|
||||
$host = getenv('DB_HOST') ?: 'localhost';
|
||||
$user = getenv('DB_USER') ?: 'root';
|
||||
$pass = getenv('DB_PASS') ?: '';
|
||||
|
||||
$conn = new mysqli($host, $user, $pass);
|
||||
if ($conn->connect_error) {
|
||||
die("<b style='color:red'>Koneksi gagal: " . $conn->connect_error . "</b>");
|
||||
}
|
||||
|
||||
$sqls = file_get_contents(__DIR__ . '/database/init.sql');
|
||||
|
||||
// Pisah per statement
|
||||
$statements = array_filter(array_map('trim', explode(';', $sqls)));
|
||||
|
||||
$success = 0;
|
||||
$errors = [];
|
||||
|
||||
foreach ($statements as $sql) {
|
||||
if (empty($sql)) continue;
|
||||
if ($conn->query($sql) === TRUE) {
|
||||
$success++;
|
||||
} else {
|
||||
$errors[] = htmlspecialchars($sql) . "<br><b style='color:red'>" . $conn->error . "</b>";
|
||||
}
|
||||
}
|
||||
|
||||
echo "<h2>DB Init Result</h2>";
|
||||
echo "<p style='color:green'>✅ $success statements executed successfully.</p>";
|
||||
|
||||
if (!empty($errors)) {
|
||||
echo "<h3 style='color:red'>Errors (" . count($errors) . "):</h3>";
|
||||
foreach ($errors as $e) {
|
||||
echo "<pre style='background:#fee;padding:8px'>$e</pre>";
|
||||
}
|
||||
} else {
|
||||
echo "<p style='color:green'>✅ All done! Semua database berhasil dibuat.</p>";
|
||||
echo "<p style='color:red'><b>⚠️ HAPUS FILE INI SEKARANG dari repo!</b></p>";
|
||||
}
|
||||
|
||||
$conn->close();
|
||||
Reference in New Issue
Block a user