<?php
/**
 * Database configuration (MySQL / MariaDB only).
 *
 * Works on any shared hosting that provides the pdo_mysql extension.
 * Values from config/installed.php (created by the installer) take
 * precedence over environment variables, so the wizard can write a
 * self-contained config without touching .env on shared hosting.
 */
$installed = file_exists(CONFIG_PATH . '/installed.php')
    ? require CONFIG_PATH . '/installed.php'
    : [];

$mysqlDefaults = [
    'host'     => $_ENV['DB_HOST'] ?? getenv('DB_HOST') ?: '127.0.0.1',
    'port'     => (int)($_ENV['DB_PORT'] ?? getenv('DB_PORT') ?: 3306),
    'database' => $_ENV['DB_NAME'] ?? getenv('DB_NAME') ?: 'pdf_forms',
    'username' => $_ENV['DB_USER'] ?? getenv('DB_USER') ?: 'app_user',
    'password' => $_ENV['DB_PASS'] ?? getenv('DB_PASS') ?: '',
    'charset'  => 'utf8mb4',
];

return [
    'driver' => 'mysql',
    'mysql'  => array_merge($mysqlDefaults, $installed['mysql'] ?? []),
];
