I am trying to fetch data from a MySQL database using python connector. I want to fetch records matching the ID
. The ID has an integer data type. This is the code:
custID = int(input("Customer ID: "))
executeStr = "SELECT * FROM testrec WHERE ID=%d"
cursor.execute(executeStr, custID)
custData = cursor.fetchall()
if bool(custData):
pass
else:
print("Wrong Id")
But the code is raising an error which says:
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 '%d' at line 1
Any ideas why the integer placeholder %d
is producing this?