我试图从MySQL数据库中检索数据。
A = "James"
query = ("SELECT * FROM DB.tblusers WHERE UserName = %s ")
c = mysql.connector.connect(user='root', password='',
host='127.0.0.1',
database='DB')
cur1 = c.cursor()
cur1.execute(query, A)
给出以下错误消息:
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 '%' at line 1
但是SQL在mySQL工作台中工作。 有什么想法吗?
A
应该是元组,请尝试使用A = ("James",)
见MySQLCursor.execute(operation, params=None, multi=False)文件
编辑:加了一个逗号,感谢“剑术”(我学到了一些东西)
相关问题 更多 >
编程相关推荐