First commit
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* WebGIS - Konfigurasi & Koneksi Database
|
||||
*/
|
||||
|
||||
// Pastikan PHP tidak menampilkan error sebagai HTML (merusak output JSON)
|
||||
ini_set('display_errors', 0);
|
||||
ini_set('display_startup_errors', 0);
|
||||
error_reporting(0);
|
||||
|
||||
define('DB_HOST', 'localhost');
|
||||
define('DB_USER', 'root');
|
||||
define('DB_PASS', '');
|
||||
define('DB_NAME', 'WEB_GIS');
|
||||
|
||||
/**
|
||||
* Mengembalikan koneksi MySQLi.
|
||||
* Jika koneksi gagal, langsung output JSON error dan exit.
|
||||
*/
|
||||
function getConnection()
|
||||
{
|
||||
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
|
||||
|
||||
if ($conn->connect_error) {
|
||||
http_response_code(500);
|
||||
echo json_encode([
|
||||
'status' => 'gagal',
|
||||
'pesan' => 'Koneksi database gagal: ' . $conn->connect_error
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$conn->set_charset('utf8mb4');
|
||||
return $conn;
|
||||
}
|
||||
Reference in New Issue
Block a user