bod114 bod114 - 1 month ago 24
MySQL Question

Python Delete not working

I don't know Syntax Error. and if can't delete then rollback data.maybe you can advise me

#!/usr/bin/python
import mysql.connector

conn= mysql.connector.connect(host='localhost',user='user',passwd='pwd',db='dest')
cursor = conn.cursor()

sql = "DELETE FROM dt WHERE user1 > "%d" % (60)
try:
try:
cursor.execute(sql)
conn.commit()
except:
conn.rollback()
except:
print "Error connect"

if conn:
conn.close()

Answer

There's a syntax error in sql =. It should be like.

sql = "DELETE FROM dt WHERE user1 > '%d' "% (60)

Hope this helps.