I'm having some troubles updating a row in a MySQL db. Here is the code I'm trying to run:
import MySQLdb
conn=MySQLdb.connect(host="localhost", user="root", passwd="pass", db="dbname")
cursor=conn.cursor()
cursor.execute("UPDATE compinfo SET Co_num=4 WHERE ID=100")
cursor.execute("SELECT Co_num FROM compinfo WHERE ID=100")
results = cursor.fetchall()
for row in results:
print row[0]
print "Number of rows updated: %d" % cursor.rowcount
cursor.close()
conn.close()
The output I get when I run this program is:
4
Number of rows updated: 1
It seems like its working but if I query the MySQL db from a MySQL Command Line I find that db was not updated at all. If however from the MySQL Command Line I enter "UPDATE compinfo SET Co_num=4 WHERE ID=100;" (without the quotes) the database is updated as expected. Do any of you have any suggestions as to what my problem may be? I'm running Python 2.5.2 with MySQL 5.1.30 on a windows box. Thanks for any help.