-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_class.py
More file actions
41 lines (35 loc) · 1.19 KB
/
db_class.py
File metadata and controls
41 lines (35 loc) · 1.19 KB
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
37
38
39
40
41
import pymysql
class db:
def __init__(self, hostname, port, username, password, databasename):
self.Connection = pymysql.connect(host=hostname, port=port, user=username, password=password,
db=databasename ,charset='utf8mb4' ,cursorclass=pymysql.cursors.DictCursor )
self.cursor = self.Connection.cursor()
def __del__(self):
self.cursor.close()
self.Connection.close()
def find(self, statement):
self.cursor.execute(statement)
buf = list()
for row in self.cursor.fetchall():
buf.append(row)
return buf
def CURD(self, statement):
try:
# Execute the SQL command
self.cursor.execute(statement)
# Commit your changes in the database
self.Connection.commit()
except:
print("Error" + statement)
# Rollback in case there is any error
self.Connection.rollback()
def CURD_SP(self, statement, title):
try:
# Execute the SQL command
self.cursor.execute(statement,(title))
# Commit your changes in the database
self.Connection.commit()
except pymysql.MySQLError as e:
print("Error: " , e)
# Rollback in case there is any error
self.Connection.rollback()