I am trying to pass a variable loc into my execute statement to get an individual slug number from my db but cant figure out how to pass it through. I have my methods set up this way because there are several different queries I will possibly perform and didnt want a bunch of repeat code.
def query(sql):
db = mysql.connector.connect(
host="localhost",
user="root",
passwd="password!",
database="db"
)
cursor = db.cursor()
cursor.execute(sql)
final_result = [i[0] for i in cursor.fetchall()]
return final_result
def individual(loc):
sql = "SELECT slug FROM auctions WHERE location = %s", loc
return query(sql)