-
Notifications
You must be signed in to change notification settings - Fork 0
/
svr_conn.py
59 lines (53 loc) · 1.17 KB
/
svr_conn.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
#svr_conn
#connect to database
#u=civconn p=civ123456
print("checking for connection...")
try:
import pymysql as ps
def test():
print("svr_conn has been imported...")
def conn():
connection = ps.connect(host = 'localhost',user = 'civconn',password = 'civ123456',database = 'civorution')
return connection
def testconn():
try:
connection = conn()
if connection.open:
return True
else:
return False
finally:
connection.close()
def checkuser(u):
try:
connection = conn()
sql = "SELECT * FROM user WHERE user=%s"
rt = connection.cursor().execute(sql,u)
return rt
finally:
connection.close()
def logup(u,p):
if checkuser(u):
return 0
else:
try:
connection = conn()
sql = "INSERT INTO user VALUES (%s,%s)"
rt = connection.cursor().execute(sql,(u,p))
connection.commit()
return rt
finally:
connection.close()
def login(u,p):
if not checkuser(u):
return -1
else:
try:
connection = conn()
sql = "SELECT * FROM user WHERE user=%s AND pswd=%s"
rt = connection.cursor().execute(sql,(u,p))
return rt
finally:
connection.close()
except:
print("conn_error")