gpt4 book ai didi

python - 如何在 Mysql Python 连接器中使用一个转义参数

转载 作者:行者123 更新时间:2023-11-29 12:24:48 25 4
gpt4 key购买 nike

我正在使用官方 MySQL Python 连接器,但是 example in the tutorial对于我正在使用的特定查询不起作用。

sql = "SHOW PROCEDURE STATUS WHERE Db = %s"
cursor.execute(sql,('testdb')) # This throws an error, sql syntax error near %s

代码cursor.execute("SHOW PROCEDURE STATUS WHERE Db = 'testdb'")工作正常

最佳答案

根据the documentationexecute 的第二个参数应该是字典或元组。 1 元素元组必须在元素后面有一个额外的逗号,以免与带括号的表达式混淆:

cursor.execute(sql,('testdb',))
# ^

关于python - 如何在 Mysql Python 连接器中使用一个转义参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28483570/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com