import mysql.connector def get_data_from_mysql(cnx, key): cursor = cnx.cursor(prepared=True) query = "SELECT field FROM items WHERE key = %s" cursor.execute(query, (key,)) total = 0 for row in cursor: total += row[0] cursor.close() return total