-
Notifications
You must be signed in to change notification settings - Fork 1
/
db.py
29 lines (23 loc) · 741 Bytes
/
db.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import mysql.connector
import os
from dotenv import load_dotenv
load_dotenv()
host = os.getenv('MYSQL_HOST')
user = os.getenv('MYSQL_USER')
password = os.getenv('MYSQL_PASSWORD')
database = os.getenv('MYSQL_DATABASE')
socket = os.getenv('MYSQL_SOCKET')
try:
con = mysql.connector.connect(host=host,database=database,user=user,password=password,unix_socket=socket)
cursor = con.cursor()
except mysql.connector.Error as err:
print (str(err))
raise
def getCursor():
try:
con = mysql.connector.connect(host=host,database=database,user=user,password=password,unix_socket=socket)
cursor = con.cursor()
except mysql.connector.Error as err:
print (str(err))
raise
return con, cursor