<?php
// Generated by setup_mariadb_project.sh — database password must come from process env.
define('DB_HOST', getenv('DB_HOST') ?: '127.0.0.1');
define('DB_NAME', getenv('DB_NAME') ?: 'app_default');
define('DB_USER', getenv('DB_USER') ?: 'app_default');
define('DB_PASS', getenv('DB_PASS') ?: '');

if (DB_PASS === '') {
  throw new RuntimeException('DB_PASS environment variable is not set.');
}

function db() {
  static $pdo;
  if (!$pdo) {
    $pdo = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME.';charset=utf8mb4', DB_USER, DB_PASS, [
      PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
      PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
    ]);
  }
  return $pdo;
}
