-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.py
63 lines (49 loc) · 1.68 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import mysql.connector as mysql
import datetime
from random import random
import numpy as np
conn = mysql.connect(host="localhost", user="root", password="", db="ecommerce")
def getNew():
cur = conn.cursor(dictionary=True)
qry = "SELECT item_id,name FROM `item` "
cur.execute(qry)
item = cur.fetchall()
return item
def checkID(userid):
cur=conn.cursor(dictionary=True)
qry="SELECT * FROM `user` WHERE `user_id`= '{}'".format(userid)
cur.execute(qry)
user = cur.fetchone()
return user
def savemsg(msg):
cur = conn.cursor(dictionary=True)
qry = "INSERT INTO `inquiry` (msg) VALUES('{}')".format(msg)
cur.execute(qry)
conn.commit()
return 0
def reg_user(userid,userpass):
cur=conn.cursor(dictionary=True)
qry = "INSERT INTO `user` (user_id,pass) VALUES('{},{}')".format(userid,userpass)
cur.execute(qry)
conn.commit()
def add_order(itm):
ordr=np.random.randint(100)
cur=conn.cursor(dictionary=True)
qry = "INSERT INTO `orders` (order_id,item_id) VALUES('{}','{}')".format(ordr,int(itm))
cur.execute(qry)
conn.commit()
qry="SELECT * FROM `orders` WHERE `order_id`= '{}'".format(ordr)
cur.execute(qry)
getordr = cur.fetchone()
return getordr
def get_order(ordr):
cur=conn.cursor(dictionary=True)
qry="SELECT * FROM `orders` WHERE `order_id`= '{}'".format(ordr)
cur.execute(qry)
getordr = cur.fetchone()
return getordr
def delete_order(ordr):
cur=conn.cursor(dictionary=True)
qry = "DELETE FROM `orders` WHERE `orders`.`order_id` = {}".format(ordr)
cur.execute(qry)
conn.commit()