Skip to content Skip to sidebar Skip to footer

Mysql Connector Could Not Process Parameters

I'm trying to loop through an array and insert each element into a table. As far as I can see my syntax is correct and I took this code straight from Microsoft Azure's documentati

Solution 1:

Try this:

for x in data:
    value = "test"
    query = "INSERT INTO test (serial) VALUES (%s)"
    cursor.execute(query,(value,))
    print("Inserted",cursor.rowcount,"row(s) of data.")

Since you are using mysql module, cursor.execute requires a sql query and a tuple as parameters

Solution 2:

Nice answer from @lucas, but maybe this help other, cz i think more cleaner

sql = "INSERT INTO your_db (your_table) VALUES (%s)"
val = [("data could be array")]
cursor = cnx.cursor()
cursor.execute(sql, val)
print("Inserted",cursor.rowcount,"row(s) of data.")
cnx.commit()
cnx.close()

Cz this is useful for my purpose, to input multiple data.

Post a Comment for "Mysql Connector Could Not Process Parameters"