Compare commits
2 Commits
21c74b6bf3
...
830b127478
| Author | SHA1 | Date | |
|---|---|---|---|
| 830b127478 | |||
| a7b5af2de8 |
+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();
|
||||||
+1
-1
@@ -14,7 +14,7 @@ services:
|
|||||||
image: mysql:8.0
|
image: mysql:8.0
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
environment:
|
environment:
|
||||||
MYSQL_ROOT_PASSWORD: rootpassword
|
MYSQL_ROOT_PASSWORD: Cb6aGo2ccTVo10wdtU3QM0Ch2yEE8Z1PR9OIXUvmKfAQrCmntWabaQa3JFqi0Vz0
|
||||||
MYSQL_DATABASE: sig_spbu
|
MYSQL_DATABASE: sig_spbu
|
||||||
volumes:
|
volumes:
|
||||||
- db_data:/var/lib/mysql
|
- db_data:/var/lib/mysql
|
||||||
|
|||||||
Reference in New Issue
Block a user