feat : db kredensial fallback
This commit is contained in:
@@ -0,0 +1,188 @@
|
||||
<?php
|
||||
// ========================================
|
||||
// FILE: php/test_koneksi.php
|
||||
// Alat Tes Koneksi Database Independen
|
||||
// ========================================
|
||||
|
||||
// Set content type to HTML
|
||||
header('Content-Type: text/html; charset=utf-8');
|
||||
|
||||
$status = null;
|
||||
$message = null;
|
||||
|
||||
// Mengambil input post jika ada
|
||||
$host = isset($_POST['host']) ? trim($_POST['host']) : '';
|
||||
$user = isset($_POST['user']) ? trim($_POST['user']) : '';
|
||||
$pass = isset($_POST['pass']) ? $_POST['pass'] : '';
|
||||
$db = isset($_POST['db']) ? trim($_POST['db']) : '';
|
||||
$port = isset($_POST['port']) ? trim($_POST['port']) : '3306';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
// Aktifkan error reporting untuk mysqli agar kita mendapat error detail
|
||||
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
|
||||
|
||||
try {
|
||||
$start_time = microtime(true);
|
||||
|
||||
// Coba hubungkan ke MySQL
|
||||
$conn = new mysqli($host, $user, $pass, $db, (int)$port);
|
||||
|
||||
$end_time = microtime(true);
|
||||
$execution_time = round(($end_time - $start_time) * 1000, 2);
|
||||
|
||||
$status = 'success';
|
||||
$message = "Koneksi Berhasil! Terhubung ke server MySQL versi " . $conn->server_info . " dalam " . $execution_time . " ms.";
|
||||
$conn->close();
|
||||
} catch (Exception $e) {
|
||||
$status = 'error';
|
||||
$message = "Koneksi Gagal: " . $e->getMessage();
|
||||
}
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="id">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>MySQL Connection Tester</title>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;600;700&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
body {
|
||||
font-family: 'Outfit', sans-serif;
|
||||
background-color: #0f172a;
|
||||
color: #f1f5f9;
|
||||
margin: 0;
|
||||
padding: 40px 20px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.card {
|
||||
width: 100%;
|
||||
max-width: 500px;
|
||||
background: rgba(30, 41, 59, 0.7);
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
border-radius: 16px;
|
||||
padding: 30px;
|
||||
box-shadow: 0 10px 30px rgba(0,0,0,0.5);
|
||||
backdrop-filter: blur(10px);
|
||||
}
|
||||
h2 {
|
||||
margin-top: 0;
|
||||
color: #38bdf8;
|
||||
font-weight: 700;
|
||||
text-align: center;
|
||||
border-bottom: 2px solid rgba(56, 189, 248, 0.2);
|
||||
padding-bottom: 15px;
|
||||
}
|
||||
.form-group {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
label {
|
||||
display: block;
|
||||
margin-bottom: 6px;
|
||||
font-weight: 600;
|
||||
color: #94a3b8;
|
||||
font-size: 14px;
|
||||
}
|
||||
input {
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
border: 1px solid rgba(255,255,255,0.1);
|
||||
border-radius: 8px;
|
||||
background: #0f172a;
|
||||
color: white;
|
||||
box-sizing: border-box;
|
||||
font-size: 14px;
|
||||
}
|
||||
input:focus {
|
||||
outline: none;
|
||||
border-color: #38bdf8;
|
||||
}
|
||||
.btn {
|
||||
width: 100%;
|
||||
background: linear-gradient(135deg, #38bdf8 0%, #0284c7 100%);
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 12px;
|
||||
border-radius: 8px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
font-size: 15px;
|
||||
transition: 0.2s;
|
||||
margin-top: 10px;
|
||||
}
|
||||
.btn:hover {
|
||||
transform: translateY(-1px);
|
||||
box-shadow: 0 4px 15px rgba(56, 189, 248, 0.4);
|
||||
}
|
||||
.alert {
|
||||
padding: 15px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 20px;
|
||||
font-size: 14px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
.alert-success {
|
||||
background-color: #dcfce3;
|
||||
color: #166534;
|
||||
border-left: 5px solid #22c55e;
|
||||
}
|
||||
.alert-error {
|
||||
background-color: #fee2e2;
|
||||
color: #991b1b;
|
||||
border-left: 5px solid #ef4444;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="card">
|
||||
<h2>🔌 MySQL Connection Tester</h2>
|
||||
|
||||
<?php if ($status !== null): ?>
|
||||
<div class="alert alert-<?php echo $status; ?>">
|
||||
<strong><?php echo $status === 'success' ? '✔ Sukses' : '❌ Gagal'; ?>:</strong>
|
||||
<?php echo htmlspecialchars($message); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form method="POST" action="">
|
||||
<div class="form-group">
|
||||
<label for="host">MySQL Host / IP Address</label>
|
||||
<input type="text" id="host" name="host" value="<?php echo htmlspecialchars($host); ?>" placeholder="Contoh: 103.xxx.xx.xx atau localhost" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group" style="display: flex; gap: 15px;">
|
||||
<div style="flex: 2;">
|
||||
<label for="user">Username</label>
|
||||
<input type="text" id="user" name="user" value="<?php echo htmlspecialchars($user); ?>" placeholder="Contoh: root" required>
|
||||
</div>
|
||||
<div style="flex: 1;">
|
||||
<label for="port">Port</label>
|
||||
<input type="text" id="port" name="port" value="<?php echo htmlspecialchars($port); ?>" placeholder="3306" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="pass">Password</label>
|
||||
<input type="password" id="pass" name="pass" value="<?php echo htmlspecialchars($pass); ?>" placeholder="Kosongkan jika tidak ada">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="db">Nama Database</label>
|
||||
<input type="text" id="db" name="db" value="<?php echo htmlspecialchars($db); ?>" placeholder="Contoh: pemetaan_kemiskinan" required>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn">Test Koneksi ⚡</button>
|
||||
</form>
|
||||
|
||||
<p style="text-align: center; margin-top: 20px; margin-bottom: 0; font-size: 13px;">
|
||||
<a href="../index.html" style="color: #38bdf8; text-decoration: none;">← Kembali ke Portal WebGIS</a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user