9

I'm trying to retrieve data from a MySQL-database.

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)

Gives the following error message:

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

But the SQL works in the mySQL Workbench. Any ideas?

Enthuziast
  • 1,195
  • 1
  • 10
  • 18

1 Answers1

23

A should be a tuple, try with A = ("James",)

see documentation of MySQLCursor.execute(operation, params=None, multi=False)


EDIT: added a comma, thanks to "swordofpain" (I learned something)