这是我的代码
qry = " INSERT INTO transactions(transaction_id,listing_id) VALUES ('%s','%s')"
cursor.execute(qry, ('123', '456',))
db_con.commit()
我收到错误消息:
(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '123'',''456'')' at line 1")
最佳答案
您正在使用SQL参数(是!),并且这些参数已经处理正确的引用了。您基本上将值用双引号引起来。从查询中删除引号:
qry = " INSERT INTO transactions(transaction_id,listing_id) VALUES (%s,%s)"
关于python - Python MySQL:插入数据时出错,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43093998/