import os
from dotenv import load_dotenv
import pymysql

load_dotenv()

try:
    connection = pymysql.connect(
        host='localhost',
        port=3306,
        user=os.getenv('DB_USER'),
        password=os.getenv('DB_PASSWORD'),
        database=os.getenv('DB_NAME')
    )
    print("✅ Verbindung erfolgreich!")
    
    with connection.cursor() as cursor:
        cursor.execute("SELECT VERSION()")
        version = cursor.fetchone()
        print(f"MariaDB Version: {version[0]}")
        
except Exception as e:
    print(f"❌ Verbindungsfehler: {e}")
finally:
    if 'connection' in locals():
        connection.close()