[英]Correct syntax to use near '%s' error while selecting data using Python from MySQL database
Running this code运行此代码
res = cursor.execute("SELECT `password` FROM `players` WHERE `username` = %s", usern)
I get this error:我收到此错误:
mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax;
mysql.connector.errors.ProgrammingError: 1064 (42000): 你的 SQL 语法有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near '%s' at line 1
查看与您的 MySQL 服务器版本相对应的手册,了解在第 1 行的“%s”附近使用的正确语法
The parametrized queries expect a tuple as an argument:参数化查询需要一个元组作为参数:
query = """SELECT `password` FROM `players` WHERE `username` = %s"""
res = cursor.execute(query, (usern, ))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.