python插入数据库
import pymysql #打开数据库连接 db= pymysql.connect(host="w1.mengting.win",user="root", password="ABCabc123!",db="ZjiteQueryData",port=3306) # 使用cursor()方法获取操作游标 cur = db.cursor() sql_insert ="""insert into UserInfo(Uid,Pwd,Run,Szf) values(4,'liu','1234')""" try: cur.execute(sql_insert) #提交 db.commit() #print('abcc') except Exception as e: #错误回滚 db.rollback() finally: db.close()
今日事今日毕