-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_userinfo_process.py
51 lines (32 loc) · 1.01 KB
/
update_userinfo_process.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
# !/usr/bin/python3
# -*- coding: utf-8 -*-
# __author__ = "Jeako_Wu"
import sql
import pymysql
from passlib.hash import sha256_crypt
def update_process(user):
try:
# 打开数据库连接
db = pymysql.connect("localhost", "root", "wujiahao.", "flaskTest")
# 使用cursor()方法获取操作游标
cursor = db.cursor()
# 查询字段
value = {}
value["phone_number"] = user.phone_number
value["password"] = sha256_crypt.hash(user.password)
# 更新条目
condition = {}
condition["name"] = user.name
# 生成SQL语句
query = sql.update("users", value, condition)
try:
# 使用execute方法执行SQL语句
if cursor.execute(query):
db.commit()
return "Successfully update"
else:
return "Update failed"
except:
return "Error while update"
except:
return "Unable to connect to DB"