Files
intranet/web/intranet_repo/general_files/ini/database.php
T

28 lines
747 B
PHP

<?php
require_once __DIR__ . '/runtime_env.php';
$host = intranet_env('DB_HOST');
$port = intranet_env('DB_PORT', '5432');
$dbname = intranet_env('DB_NAME');
$username = intranet_env('DB_USER');
$password = intranet_env('DB_PASSWORD');
try {
$pdo = new PDO(
"pgsql:host={$host};port={$port};dbname={$dbname}",
$username,
$password,
[
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
]
);
} catch (PDOException $e) {
error_log('Database connection failed: ' . $e->getMessage());
http_response_code(500);
exit('Database connection failed.');
}
return $pdo;