How To Pass Variables To Mysql Using Python
I am using MYSQL (ver. 5.5.31-0+wheezy1) and python (ver. 2.7.3) with the following statement: q ='''INSERT INTO scale_equipment truck_id, product_id, driver_id, field_id, pit_id,
Solution 1:
Query parameters should must be passed in the second argument of execute()
:
params = ('002', 'CS', 'BG', 'HD1', 'T1', 'C1', 0, 'U')
cursor.execute("""INSERT INTO
scale_equipment
(truck_id, product_id, driver_id, field_id, pit_id, harvest_equipment_id, weight, status)
VALUES
(%s, %s, %s, %s, %s, %s, %s, %s)""", params)
In this case you wouldn't worry about sql injections, mysqldb driver does escaping for you.
Post a Comment for "How To Pass Variables To Mysql Using Python"