我试图通过Flask的MySQLdb模块执行以下操作:
cur.execute("SELECT post_id FROM tbl_post WHERE post_file_path = '%s'", (_filePath,))
然而我收到以下错误:
1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'static/uploads/adc67db4-7d23-4bf1-a7ef-7e34dbed246a.jpg''' at line 1"
通过命令行查询工作正常,所以我相当肯定它与我提供字符串参数的方式有关。我做错了什么?
答案 0 :(得分:2)
您不应该引用占位符%s
,它是由数据库驱动程序完成的。这应该有效:
cur.execute("SELECT post_id FROM tbl_post WHERE post_file_path = %s", (_filePath,))