<?php
require_once __DIR__ . '/../app/helpers/env.php';
loadEnv();

function getConnection()
{
    $serverName = $_ENV['DB_HOST'];
    $connectionOptions = [
        "Database" => $_ENV['DB_DATABASE'],
        "Uid" => $_ENV['DB_USERNAME'],
        "PWD" => $_ENV['DB_PASSWORD'],
        "CharacterSet" => "UTF-8"
    ];

    $conn = sqlsrv_connect($serverName, $connectionOptions);

    if (!$conn) {
        die("❌ Error al conectar: " . print_r(sqlsrv_errors(), true));
    }

    return $conn;
}
