Skip to content Skip to sidebar Skip to footer

How To Use Variables In Python Sql Query?

I'm using some copy-pasted code to do SQL queries on a MySQL DB through Python/Flask. I'm not familiar with it and it's telling me the way I'm trying to input a variable is not the

Solution 1:

You can use %s as a placeholder for the bound value:

query = """SELECT * FROM users WHERE email = %s"""
result = cursor.execute(query, (val,))

Post a Comment for "How To Use Variables In Python Sql Query?"