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