python 3.8.1 ,pymysql 0.9.3
放报错代码import pymysql
def getCollectToMysql():
# 打开数据库连接
dbConnect = pymysql.connect(host='localhost',user='root',passwd='root',db='issuehandledb',port=3306,charset='utf8')
# 使用cursor()方法获取操作游标
cursor = dbConnect.cursor()
return cursor, dbConnect
#使用列表内元组的方式增加
def insertDataToMysql(cursor, dbConnect, insertData, sql):
try:
cursor.execute(sql, insertData)
dbConnect.commit()
except:
# Rollback in case there is any error
# 输出异常信息
print(insertData)
traceback.print_exc()
dbConnect.rollback()
if __name__ == '__main__':
cursor,dbConnect = getCollectToMysql()
insertsql = 'insert into issuehandledb.userinfo(id,username,password,privilege,isused) values(%d,%s,%s,%d,%s);'
result = (8,'xccc','sss',4,'1')
insertDataToMysql(cursor,dbConnect,result,insertsql)
cursor.close()
dbConnect.close()
报错如下:
原创文章 1获赞 1访问量 21
关注
私信
展开阅读全文
作者:圈点圈点圈