Compare commits

...

7 commits

2 changed files with 8 additions and 17 deletions

View file

@ -17,7 +17,7 @@ import pymysql
import sys
# Read conf.ini
INI_CONF = "./config/sql_conf.ini"
INI_CONF = "./config/mysql_conf.ini"
if os.path.exists(INI_CONF) is False:
print("MySQL configuration error, {}: file not found".format(INI_CONF))
@ -27,25 +27,15 @@ CONFIG = ConfigParser()
CONFIG.read(INI_CONF)
# DB parameters
SQL_HOST = CONFIG.get('sql', 'host')
SQL_DB = CONFIG.get('sql', 'database')
SQL_USER = CONFIG.get('sql', 'user')
SQL_PWD = CONFIG.get('sql', 'passwd')
SQL_HOST = CONFIG.get('mysql', 'host')
SQL_DB = CONFIG.get('mysql', 'database')
SQL_USER = CONFIG.get('mysql', 'user')
SQL_PWD = CONFIG.get('mysql', 'passwd')
class HandleSql:
"""Class to handle sql connection."""
@staticmethod
def sql_checkcon():
"""Init sql connection."""
try:
global conn
conn = pymysql.connect(host=SQL_HOST, db=SQL_DB, user=SQL_USER, passwd=SQL_PWD)
cur = conn.cursor()
except pymysql.DatabaseError as error:
print(error)
@staticmethod
def sql_conn():
"""Init sql connection."""
@ -53,6 +43,7 @@ class HandleSql:
global conn
conn = pymysql.connect(host=SQL_HOST, db=SQL_DB, user=SQL_USER, passwd=SQL_PWD)
cur = conn.cursor()
return True
except pymysql.DatabaseError as error:
print(error)

View file

@ -3,10 +3,10 @@
from manage_sql.manage_sql import HandleSql
MY_SQL_CONN = HandleSql()
MYSQL_CONN = HandleSql()
try:
check_return_bdd = MY_SQL_CONN.sql_checkcon()
check_return_bdd = MYSQL_CONN.conn()
except OperationalError as error:
print(error)
else: