# This file contains the function to connect to a secified database. import json import mariadb import sys # Open the config file and readout the data with open(r'C:\Users\Nico\Desktop\Gitea\PlantSensorAPI\SQLHandler\config.json', 'r') as file: data = file.read() config = json.loads(data) # -------------------------------------------------------------------------------------------------------------------- # def createConnection(configuration): """ It creates the connection to the database :param configuration: This specifies which configuration should be used :return: It returns the database connection """ try: connection = mariadb.connect( host=config["host"], user=config["user"], password=config["passwd"], database=config["dbname"], autocommit=True ) except mariadb.Error as e: print(f"Error connecting to MariaDB Platform: {e}") sys.exit(1) return connection