This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
import mysql.connector, os
from dotenv import load_dotenv
load_dotenv()
def get_db_connection():
try:
db_host = os.getenv("DB_HOST")
db_user = os.getenv("DB_USER")
db_pass = os.getenv("DB_PASS")
db_name = os.getenv("DB_NAME")
db = mysql.connector.connect(host=db_host, user=db_user, password=db_pass, database=db_name)
except mysql.connector.Error as err:
print(f"❌ Failed to connect to DB: {err}")
return # don’t continue if DB failed
return db