forked from librahfacebook/Face
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserManage.py
51 lines (45 loc) · 1.3 KB
/
UserManage.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
'''
将用户信息进行保存并上传到个人数据库内
'''
import pymysql
class DBHelper:
def __init__(self, host='127.0.0.1', user='root',
pwd='158968', db='face'):
self.host = host
self.user = user
self.pwd = pwd
self.db = db
self.conn = None
# 连接数据库
def connect(self):
try:
self.conn = pymysql.connect(self.host, self.user,
self.pwd, self.db, charset='utf8')
except:
print("connect error...")
return False
self.cur = self.conn.cursor()
return True
# 关闭数据库
def close(self):
if self.conn and self.cur:
self.cur.close()
self.conn.close()
return True
# 插入操作,执行数据库语句
def execute(self, sql, params=None):
# 连接数据库
self.connect()
try:
if self.conn and self.cur:
self.cur.execute(sql, params)
self.conn.commit()
except:
print("insert error...")
self.close()
return False
return True
# 查询表数据
def fetchall(self, sql, params=None):
self.execute(sql, params)
return self.cur.fetchall()