32 lines
816 B
Python
32 lines
816 B
Python
import mysql.connector
|
|
import pydapper
|
|
import logging
|
|
import json
|
|
import os
|
|
|
|
connection_pool = None
|
|
|
|
def initPool():
|
|
try:
|
|
global connection_pool
|
|
|
|
config_path = './src/server/BreCal/connection_data.json'
|
|
print (os.getcwd())
|
|
if not os.path.exists(config_path):
|
|
print ('cannot find ' + config_path)
|
|
exit(1)
|
|
|
|
f = open(config_path);
|
|
connection_data = json.load(f)
|
|
|
|
connection_pool = mysql.connector.connect(**connection_data)
|
|
|
|
commands = pydapper.using(connection_pool)
|
|
data = commands.query_single("SELECT id from `user`")
|
|
print("DB connection successful")
|
|
|
|
except mysql.connector.PoolError as e:
|
|
logging.error(f"Failed to create connection pool: {e}")
|
|
print(e)
|
|
except e:
|
|
print(e) |