<?php
/**
 * EnglishSpeak - Database Configuration
 *
 * Uses PDO with exception mode and UTF-8 mb4.
 * Default Laragon settings: host=localhost, user=root, password=(empty).
 */

function getDbConnection(): PDO
{
    static $pdo = null;

    if ($pdo === null) {
        $host    = 'localhost';
        $dbname  = 'sieuth54_englishspeak';
        $charset = 'utf8mb4';
        $user    = 'sieuth54_englishspeak';
        $pass    = 'Thpn2022@';

        $dsn = "mysql:host={$host};dbname={$dbname};charset={$charset}";

        $options = [
            PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
            PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
            PDO::ATTR_EMULATE_PREPARES   => false,
        ];

        $pdo = new PDO($dsn, $user, $pass, $options);
    }

    return $pdo;
}