18 lines
495 B
Python
18 lines
495 B
Python
import os, mysql.connector
|
|
from dotenv import load_dotenv
|
|
from pathlib import Path
|
|
|
|
# charge le .env **avec chemin absolu**
|
|
load_dotenv(Path(__file__).resolve().parent.joinpath(".env"))
|
|
|
|
conn = mysql.connector.connect(
|
|
host=os.getenv("DB_HOST"),
|
|
user=os.getenv("DB_USER"),
|
|
password=os.getenv("DB_PASSWORD"),
|
|
database=os.getenv("DB_NAME"),
|
|
connection_timeout=5,
|
|
)
|
|
conn.ping(reconnect=True, attempts=3, delay=1)
|
|
print("CONNECTED" if conn.is_connected() else "KO")
|
|
conn.close()
|