如何在mysql和python中使用绑定变量

2024-09-30 20:37:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我将mysql与python一起使用,使用绑定变量时出错。实际上我不知道如何使用绑定变量。请帮我解决我的问题

这是我的密码:

iouNo=textiv1.get()
    cursor.execute("UPDATE iou_table SET IOU_status=4 WHERE IOU_No= :iouNo",{'iouNo':iouNo})
    mydb.commit()

这就是我犯的错误

mysql.connector.errors.ProgrammingError: 1064 (42000): 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 ':'iouNo'' at line 1

我想在SQL查询中使用iouNo变量。。。我怎么做


Tags: theto密码executesqlyourgetmysql
1条回答
网友
1楼 · 发布于 2024-09-30 20:37:59

你可以在MySQL的manual中读到这方面的内容

%s用作占位符

如果您只有一个参数或变量,您仍然需要使用二维元组

iouNo=textiv1.get()
cursor.execute("UPDATE iou_table SET IOU_status=4 WHERE IOU_No= %s;",(iouNo,))
mydb.commit()

相关问题 更多 >