import pymysql
mysql_client =pymysql.Connect('127.0.0.1','root','18603503110','1712B',3306,charset='utf8')
# 创建游标(执行mysql语句)
cursor = mysql_client.cursor()
sql = """
INSERT INTO ...(%s)
VALUE (%s)
"""%(','.join(dict.keys()),','.join(['%s']*len(dict)))
try:
cursor.execute(sql,list(dict.values()))
mysql_client.commit()
except Exception as err:
print(err)
mysql_client.rollback()
网友评论