Skip to content
Advertisement

how to use multi variables in a single SQL python code

I have used this code to use two variables in a single SQL code in Python :

cursor.execute("select * from customers WHERE username=%s and password=%s", (a, b))

but I’ve got this error :

MySQLInterfaceError: Python type tuple cannot be converted

though I’ve converted my strings into a tuple like this:

a = tuple(map(str, emaile.split(",")))
b = tuple(map(str, passe.split(",")))

how can I use these two variables in my cursor.execute code?

Advertisement

Answer

query = """select * from customers WHERE username=%s and password=%s"""
tuple1 = ("mini", 9000)
cursor.execute(query, tuple1)
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement