Added SQL, dao and app - not functional
This commit is contained in:
28
functions/database.py
Normal file
28
functions/database.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import mysql.connector
|
||||
from mysql.connector import Error
|
||||
from config.db_config import db_config
|
||||
|
||||
def get_db_connection():
|
||||
try:
|
||||
connection = mysql.connector.connect(**db_config)
|
||||
return connection
|
||||
except Error as e:
|
||||
print(f"Error connecting to database: {e}")
|
||||
return None
|
||||
|
||||
def execute_query(query, params=None):
|
||||
connection = get_db_connection()
|
||||
if connection is None:
|
||||
return None
|
||||
try:
|
||||
cursor = connection.cursor(dictionary=True)
|
||||
cursor.execute(query, params)
|
||||
connection.commit()
|
||||
return cursor
|
||||
except Error as e:
|
||||
print(f"Error executing query: {e}")
|
||||
return None
|
||||
finally:
|
||||
if connection.is_connected():
|
||||
cursor.close()
|
||||
connection.close()
|
||||
Reference in New Issue
Block a user