-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdb.py
36 lines (29 loc) · 1.07 KB
/
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
30
31
32
33
34
35
36
import mysql.connector
class Database:
def __init__(self):
self.connection = mysql.connector.connect(host = "localhost", user = "root",passwd = "root", database = "face_recognition2", auth_plugin="mysql_native_password")
print("connection established")
def query(self, q, arg=()):
cursor = self.connection.cursor(buffered=True)
cursor.execute(q, arg)
results = cursor.fetchall()
cursor.close()
return results
def insert(self, q, arg=()):
cursor = self.connection.cursor(buffered=True)
cursor.execute(q, arg)
self.connection.commit()
result = cursor.lastrowid
cursor.close()
return result
def select(self, q, arg=()):
cursor = self.connection.cursor(buffered=True)
cursor.execute(q, arg)
results = cursor.fetchall()
cursor.close()
return results
def delete(self, q, arg=()):
cursor = self.connection.cursor(buffered=True)
result = cursor.execute(q, arg)
self.connection.commit()
return result