update config

This commit is contained in:
Abimanyu Ridho
2026-06-11 14:15:44 +07:00
parent 124f91c778
commit c86b2890f1
+17
View File
@@ -5,6 +5,23 @@ mysqli_report(MYSQLI_REPORT_OFF);
if (!function_exists('loadDatabaseConfig')) {
function loadDatabaseConfig(): array {
// Load .env if exists
$envFile = dirname(__DIR__, 2) . '/.env';
if (file_exists($envFile)) {
$lines = file($envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($lines as $line) {
if (strpos(trim($line), '#') === 0) continue;
list($name, $value) = explode('=', $line, 2);
$name = trim($name);
$value = trim($value);
if (!array_key_exists($name, $_SERVER) && !array_key_exists($name, $_ENV)) {
putenv(sprintf('%s=%s', $name, $value));
$_ENV[$name] = $value;
$_SERVER[$name] = $value;
}
}
}
$config = [
'host' => getenv('DB_HOST') ?: '127.0.0.1',
'user' => getenv('DB_USER') ?: 'root',