<?php

namespace Config;

use PDO;
use PDOException;

class Database
{
    private static $host = 'localhost';
    private static $dbname = 'ugelsant_mpv';
    private static $username = 'ugelsant_gestor';
    private static $password = 'Josecas2024**';
    private static $connection = null;
    
    public static function getConnection()
    {
        if (self::$connection === null) {
            try {
                self::$connection = new PDO(
                    "mysql:host=" . self::$host . ";dbname=" . self::$dbname . ";charset=utf8",
                    self::$username,
                    self::$password,
                    [
                        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
                        PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
                        PDO::ATTR_EMULATE_PREPARES => false
                    ]
                );
            } catch (PDOException $e) {
                die("Error de conexi車n a la base de datos: " . $e->getMessage());
            }
        }
        return self::$connection;
    }
}
