Skip to content Skip to sidebar Skip to footer

Using A Python Variable In Mysql Query

I am trying to write a function that takes the variable written in the function placeholder() written below and then uses that in MySQL queries. I have written up an example below:

Solution 1:

sql = "TRUNCATE TABLE " + placeholder_variable + ";"
cursor.execute(sql)

Solution 2:

SQL parameters cannot be used for metadata with MySQL. You will need to sanitize the value and substitute it normally.


Post a Comment for "Using A Python Variable In Mysql Query"