-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqlConnect.py
More file actions
41 lines (38 loc) · 943 Bytes
/
sqlConnect.py
File metadata and controls
41 lines (38 loc) · 943 Bytes
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
#sql connect
import pymysql
config = {
'host': '127.0.0.1',
'port': 3306,
'user': 'root',
'passwd': 'lyf110110@LYF',
'db': 'users_ccu',
'charset': 'utf8'
}
db = pymysql.connect(**config)
cursor = db.cursor()
def query_imei_imsi(xh):
sql = 'select imei, imsi from jkwx where jkwx.xh='+ xh +';'
cursor.execute(sql)
res = cursor.fetchall()
return res[0][0], res[0][1]
def query_data(now):
sql = "select xh from jkwx where jkwx.over=0 and jkwx.date !=%d;" % now
cursor.execute(sql)
res = cursor.fetchall()
#print(res)
return res
def update_data(xh, s, now):
if(s>=80.0):
over = 1
else:
over = 0
sql = "update jkwx set jkwx.km=%.3f, jkwx.over=%d, jkwx.date=%d where jkwx.xh=%s" % (s, over, now, xh)
try:
cursor.execute(sql)
db.commit()
return True
except:
db.rollback()
return False
def db_close():
db.close()