feat : db kredensial fallback

This commit is contained in:
unknown
2026-06-12 23:04:30 +07:00
parent d7dd18ddba
commit bb883473e4
2 changed files with 202 additions and 9 deletions
+14 -9
View File
@@ -34,17 +34,22 @@ try {
// 1. Coba koneksi utama sesuai konfigurasi Environment / Env File
$conn = new mysqli($host, $username, $password, $database, (int)$port);
} catch (Exception $e) {
// 2. Coba koneksi Fallback ke Docker Host (host.docker.internal)
// 2. Coba koneksi Fallback Pertama: Backup Kredensial Keras Database Coolify (Internal Network)
try {
$conn = new mysqli("host.docker.internal", "root", "", "pemetaan_kemiskinan", 3306);
} catch (Exception $e_docker) {
// 3. Coba koneksi Fallback ke Localhost murni
$conn = new mysqli("tk4ksw0w40kg080wkk4soww4", "mysql", "KBw0yKLccMMoBOZJCf8WDHAO93uI65om0s4ajnzQEt5mkuh0NaIytoWb7TgR5ciq", "default", 3306);
} catch (Exception $e_backup) {
// 3. Coba koneksi Fallback Kedua ke Docker Host lokal (host.docker.internal)
try {
$conn = new mysqli("localhost", "root", "", "pemetaan_kemiskinan", 3306);
} catch (Exception $e_local) {
// Jika semua gagal, berikan respon error
sendJSON('error', 'Koneksi database utama & fallback gagal: ' . $e_local->getMessage());
exit();
$conn = new mysqli("host.docker.internal", "root", "", "pemetaan_kemiskinan", 3306);
} catch (Exception $e_docker) {
// 4. Coba koneksi Fallback Ketiga ke Localhost murni (XAMPP default)
try {
$conn = new mysqli("localhost", "root", "", "pemetaan_kemiskinan", 3306);
} catch (Exception $e_local) {
// Jika semua gagal, berikan respon error
sendJSON('error', 'Koneksi database utama & seluruh fallback gagal. Error Utama: ' . $e->getMessage() . ' | Error Backup: ' . $e_backup->getMessage());
exit();
}
}
}
}