parent
47b8de55bb
commit
46cb866ad1
@ -0,0 +1,24 @@
|
||||
import mysql.connector
|
||||
from mysql.connector import Error
|
||||
import configparser
|
||||
|
||||
def load_config():
|
||||
config = configparser.ConfigParser()
|
||||
config.read('config.ini')
|
||||
return config
|
||||
|
||||
def connect_to_database():
|
||||
try:
|
||||
config = load_config()
|
||||
connection = mysql.connector.connect(
|
||||
host=config['database']['host'],
|
||||
database=config['database']['database'],
|
||||
user=config['database']['user'],
|
||||
password=config['database']['password']
|
||||
)
|
||||
if connection.is_connected():
|
||||
print("Connected to the database successfully!")
|
||||
return connection
|
||||
except Error as e:
|
||||
print(f"Error while connecting to database: {e}")
|
||||
return None
|
Loading…
Reference in new issue