vairable不会通过python传递到mysql

时间:2018-07-17 02:13:06

标签: python mysql

我正在尝试将varible传递给mysql,但它不会插入表中,并且在python中没有发生错误。

db = pymysql.connect("localhost", "root", "1234", "vehiclerecord")
cursor = db.cursor() 
params =('7',vehicle_no,'2')

sql ="""INSERT INTO vehiclerecord.v_entry (v_id, v_no, v_type) VALUES (%S,%S,%S)""",(params)

try:      
cursor.execute(sql)
db.commit()

except:
      db.rollback()

db.close()

1 个答案:

答案 0 :(得分:2)

代替:

sql ="""INSERT INTO vehiclerecord.v_entry (v_id, v_no, v_type) VALUES (%S,%S,%S)""",(params)

cursor.execute(sql)

您应该:

sql ="""INSERT INTO vehiclerecord.v_entry (v_id, v_no, v_type) VALUES (%S,%S,%S)"""

cursor.execute(sql, params)