From c86b2890f16389588686df728a191f66332292aa Mon Sep 17 00:00:00 2001 From: Abimanyu Ridho Date: Thu, 11 Jun 2026 14:15:44 +0700 Subject: [PATCH] update config --- api/config/database.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/api/config/database.php b/api/config/database.php index e5664d9..c516509 100644 --- a/api/config/database.php +++ b/api/config/database.php @@ -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',