In the code below, i have a string which represent the mac number. I want to use it in my query. Normally it will change dynamically, because of that i want to use it as this way. Is there another easy way to use my string active_mac in the query? Like "select epp_group_id from epp_inventory where epp_active_mac = " + active_mac
import os
import mysql.connector
from mysql.connector.constants import ClientFlag
import json
active_mac = "b45d50cfef6a"
active_mac_upper = active_mac.upper()
print(active_mac_upper)
mydb = mysql.connector.connect(
host="localhost",
user="VAadmin",
password="991550sE*",
database="VA"
)
mycursor = mydb.cursor()
sql = "select epp_group_id from epp_inventory where epp_active_mac = %s"
adr = (active_mac_upper,)
mycursor.execute(sql, adr)
#mycursor.execute("select epp_group_id from epp_inventory where epp_active_mac = '%s'")
myresult = mycursor.fetchall()
for x in myresult:
print(x)