python-flaskmysql数据库交互语句

it2022-07-04  142

1.导入pymsql

import pymysql

2.数据库条件查询语句

db = pymysql.connect("localhost", "root", "", "test") cursor = db.cursor() cursor.execute("select * from user where username=%s and password=%s", (user_name,user_pwd)) db.commit()

3.数据库条件更新语句

db = pymysql.connect("localhost", "root", "", "test") cursor = db.cursor() cursor.execute("UPDATE work SET off=%s , deltime=%s where username=%s and dates=%s", ((now2),(b-a),user_name,date)) db.commit()

4.数据库插入语句

db = pymysql.connect("localhost", "root", "", "test") cursor = db.cursor() cursor.execute("INSERT INTO user(username,password,email,age,birthday)values (%s,%s,%s,%s,%s)", (user.name,user.pwd,user.email,user.age,user.birthday)) db.commit()

最新回复(0)