You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
946 B
Python

# This file contains the function to connect to a secified database.
import json
import mysql.connector
# Open the config file and readout the data
with open('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
"""
connection = mysql.connector.connect(
host=config[configuration]["host"],
user=config[configuration]["user"],
password=decryption.decryptKey(config[configuration]["passwd"]),
database=config[configuration]["dbname"],
autocommit=True
)
return connection