-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataBase.py
33 lines (26 loc) · 1.03 KB
/
DataBase.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
30
31
32
##################################### DataBase #################################
''' serve python-mysqldb --> apt install python-mysqldb '''
import MySQLdb
from utils import *
class DataBase:
def __init__(self, config):
try:
self.db_connection = MySQLdb.connect(host=config['db_host'],
user=config['db_user'],
passwd=config['db_passwd'],
db=config['db_name'])
print("[DATABASE] connesso")
except:
print("[DATABASE] non riesco a connettermi al database")
quit()
# creo il cursore per utilizzare il database
self.db = self.db_connection.cursor()
#eseguo la query e aggiorno il database
#ritorno il risultato della query
def execute(self, query):
self.db.execute(query)
self.db_connection.commit()
return self.db.fetchall()
#chiude la connessione con il database
def close(self):
self.db_connection.close()