import os
import mysql.connector
from dotenv import load_dotenv

# Carga el .env si existe (local). Si no, usa las variables del servidor.
load_dotenv()

def get_connection():
    return mysql.connector.connect(
        host=os.getenv("DB_HOST", "127.0.0.1"),
        user=os.getenv("DB_USER", "root"),
        password=os.getenv("DB_PASSWORD", ""),
        database=os.getenv("DB_NAME", "utrau_app_db"),
        port=int(os.getenv("DB_PORT", 3306))
    )