31 lines
514 B
Python
31 lines
514 B
Python
|
|
import mariadb
|
|
import os
|
|
from dotenv import load_dotenv
|
|
|
|
load_dotenv()
|
|
|
|
def db_connection():
|
|
try:
|
|
connection = mariadb.connect(
|
|
host=os.getenv("DB_HOST", "localhost"),
|
|
port=int(os.getenv("DB_PORT", 3306)),
|
|
user=os.getenv("DB_USER"),
|
|
password=os.getenv("DB_PASSWORD"),
|
|
database=os.getenv("DB_NAME")
|
|
)
|
|
return connection
|
|
except mariadb.Error as e:
|
|
raise RuntimeError(f"Fehler beim Verbinden mit DB: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|