Home > other >  how to use multi variables in a single SQL python code
how to use multi variables in a single SQL python code

Time:08-15

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?

CodePudding user response:

query = """select * from customers WHERE username=%s and password=%s"""
tuple1 = ("mini", 9000)
cursor.execute(query, tuple1)

CodePudding user response:

cursor.execute("INSERT INTO table VALUES (%s, %s, %s)", (var1, var2, var3))

  • Related