<div dir="ltr">I am trying to write a program that will loop through a text file and delete rows in a mysql database.<div><br clear="all"><div>It seemingly runs but I don't see anything getting deleted in the db.</div>
<div>Is there anything apparent that I am missing?</div><div><br></div><div>This is the code:</div><div><div>#!/usr/bin/python</div><div>import mysql.connector</div><div>#</div><div>f=open('/home/smithm/email-list.txt', 'r')</div>
<div>for line in f:</div><div> #<do something with line></div><div> # Open database connection</div><div> db = mysql.connector.connect(user="xx", password="xx", host="localhost", database="xx")</div>
<div><br></div><div> # prepare a cursor object using cursor() method</div><div> cursor = db.cursor()</div><div><br></div><div> # Prepare SQL query to DELETE required records </div><div> sql = "DELETE FROM tblc_users WHERE user_email=%s, % (line)"</div>
<div> try:</div><div> # Execute the SQL command</div><div> cursor.execute(sql)</div><div> # Commit your changes in the database</div><div> db.commit()</div><div> except:</div>
<div> # Rollback in case there is any error</div><div> db.rollback()</div><div><br></div><div> # disconnect from server</div><div> db.close()</div></div><div><br></div>-- <br><div>Matthew Smith</div>
<div><br></div>
</div></div>