python里面链接mysql,写SQL语句,传递变量的问题

2025-02-26 18:52:49
推荐回答(3个)
回答1:

query="select task_type from task_type_table where module_name=%s and task_name=%s"
cursor_fetch.execute(query, [var1, var2])
results=cursor_fetch.fetchall()
我这样的sql查询是没问题的
你的出错可能是字符串缺少引号的缘故吧

回答2:

query="select task_type from task_type_table where module_name=%(MODULE_NAME)s and task_name=%(TASK_NAME_img)s"
cursor_fetch.execute(query, vars())
results=cursor_fetch.fetchall()

回答3:

感觉没有错,把报的错误贴出来吧