在Python3.3中使用%s的SQL查询

2024-06-23 02:29:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图从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工作台中工作。 有什么想法吗?


Tags: theto数据数据库dbsqlyourconnector