I have used this code to use two variables in a single SQL code in Python :
JavaScript
x
2
1
cursor.execute("select * from customers WHERE username=%s and password=%s", (a, b))
2
but I’ve got this error :
MySQLInterfaceError: Python type tuple cannot be converted
though I’ve converted my strings into a tuple like this:
JavaScript
1
3
1
a = tuple(map(str, emaile.split(",")))
2
b = tuple(map(str, passe.split(",")))
3
how can I use these two variables in my cursor.execute
code?
Advertisement
Answer
JavaScript
1
4
1
query = """select * from customers WHERE username=%s and password=%s"""
2
tuple1 = ("mini", 9000)
3
cursor.execute(query, tuple1)
4