-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.py
43 lines (38 loc) · 991 Bytes
/
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
33
34
35
36
37
38
39
40
41
42
43
import mysql.connector
password=""
database="blockchain"
def select(q):
cnx=mysql.connector.connect(user='root',host='localhost',password=password,database=database)
cur=cnx.cursor(dictionary=True)
cur.execute(q)
result=cur.fetchall()
cnx.close()
cur.close()
return result
def delete(q):
cnx=mysql.connector.connect(user='root',host='localhost',password=password,database=database)
cur=cnx.cursor(dictionary=True)
cur.execute(q)
cnx.commit()
result=cur.rowcount
cnx.close()
cur.close()
return result
def update(q):
cnx=mysql.connector.connect(user='root',host='localhost',password=password,database=database)
cur=cnx.cursor(dictionary=True)
cur.execute(q)
cnx.commit()
result=cur.rowcount
cnx.close()
cur.close()
return result
def insert(q):
cnx=mysql.connector.connect(user='root',host='localhost',password=password,database=database)
cur=cnx.cursor(dictionary=True)
cur.execute(q)
cnx.commit()
result=cur.lastrowid
cnx.close()
cur.close()
return result