I want to get the index of a field that has a specific word in its name:
mydb_f = mysql.connector.connect(host="localhost", user="user", passwd="ABCD@9273", database="mydb")
mycursor_f = mydb_f.cursor()
table_name_contains = "myword"
table = "mytable"
mycursor_f.execute("SHOW COLUMNS FROM mydb.%s LIKE '%%%s%%';" % (table, table_name_contains))
myresult_f = mycursor_f.fetchone()
field_index = myresult_f[0]
print(field_index)
but no luck and get syntax error.
New contributor
Mahdi Talebi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.