Files
UAS_WEBGIS_CindyDyraIslamay…/01SPBU/koneksi.php
T
2026-06-10 19:20:46 +07:00

30 lines
656 B
PHP

<?php
// Set header JSON untuk semua response
header('Content-Type: application/json');
$host = 'localhost';
$user = 'root';
$password = ''; // Pastikan password MySQL Anda
$database = 'webgis';
try {
// Buat koneksi
$conn = new mysqli($host, $user, $password, $database);
// Cek koneksi
if ($conn->connect_error) {
throw new Exception("Koneksi gagal: " . $conn->connect_error);
}
// Set charset
$conn->set_charset("utf8");
} catch (Exception $e) {
// Jika error, tetap kembalikan JSON
echo json_encode([
'status' => 'error',
'message' => $e->getMessage()
]);
exit;
}
?>