evol 2
This commit is contained in:
0
utils/db/__init__.py
Normal file
0
utils/db/__init__.py
Normal file
22
utils/db/connect_db
Normal file
22
utils/db/connect_db
Normal file
@@ -0,0 +1,22 @@
|
||||
import logging
|
||||
import mysql.connector
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def conn_db(cfg):
|
||||
"""Establishes a connection to the MySQL database.
|
||||
|
||||
Args:
|
||||
cfg: The configuration object containing database connection details.
|
||||
|
||||
Returns:
|
||||
A MySQL database connection object.
|
||||
"""
|
||||
try:
|
||||
conn = mysql.connector.connect(user=cfg.dbuser, password=cfg.dbpass, host=cfg.dbhost, port=cfg.dbport)
|
||||
conn.autocommit = True
|
||||
return conn
|
||||
except mysql.connector.Error as e:
|
||||
logger.error(f'{e}')
|
||||
exit(e.errno)
|
||||
return None
|
||||
Reference in New Issue
Block a user