initial commit
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
<IfModule mod_authz_core.c>
|
||||
Require all denied
|
||||
</IfModule>
|
||||
<IfModule !mod_authz_core.c>
|
||||
Deny from all
|
||||
</IfModule>
|
||||
|
||||
# Disable directory listing
|
||||
Options -Indexes
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'host' => 'localhost',
|
||||
'user' => 'root',
|
||||
'pass' => 'password',
|
||||
'name' => 'webgis_poverty',
|
||||
'charset' => 'utf8mb4',
|
||||
];
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
// api/config/database.php
|
||||
|
||||
mysqli_report(MYSQLI_REPORT_OFF);
|
||||
|
||||
if (!function_exists('loadDatabaseConfig')) {
|
||||
function loadDatabaseConfig(): array {
|
||||
$config = [
|
||||
'host' => getenv('DB_HOST') ?: 'localhost',
|
||||
'user' => getenv('DB_USER') ?: 'root',
|
||||
'pass' => getenv('DB_PASS') ?: '',
|
||||
'name' => getenv('DB_NAME') ?: 'webgis_poverty',
|
||||
'charset' => getenv('DB_CHARSET') ?: 'utf8mb4',
|
||||
];
|
||||
|
||||
$localConfigFile = __DIR__ . '/database.local.php';
|
||||
if (is_file($localConfigFile)) {
|
||||
$localConfig = require $localConfigFile;
|
||||
if (is_array($localConfig)) {
|
||||
$config = array_merge($config, array_intersect_key($localConfig, $config));
|
||||
}
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
}
|
||||
|
||||
$dbConfig = loadDatabaseConfig();
|
||||
|
||||
define('DB_HOST', $dbConfig['host']);
|
||||
define('DB_USER', $dbConfig['user']);
|
||||
define('DB_PASS', $dbConfig['pass']);
|
||||
define('DB_NAME', $dbConfig['name']);
|
||||
define('DB_CHARSET', $dbConfig['charset']);
|
||||
|
||||
function getDB(): mysqli {
|
||||
static $conn = null;
|
||||
if ($conn === null) {
|
||||
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
|
||||
if ($conn->connect_error) {
|
||||
error_log('DB connection failed: ' . $conn->connect_error);
|
||||
http_response_code(500);
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'Koneksi database gagal'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
$conn->set_charset(DB_CHARSET);
|
||||
}
|
||||
return $conn;
|
||||
}
|
||||
Reference in New Issue
Block a user