Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's wrong with my Python code to update MySQL table where ID = an integer?

>>> print x 
 [(1,), (2,), (3,), (4,), (5,), (6,), (7,), (8,), (9,), (10,)]

>>> for i in range(10):
...     if len(x)>0:
...             m = random.choice(x)
...             x.remove(m)
...             y = "%s" %m
...             z = int(y)
...             cur.execute("""UPDATE accounts SET column = 'YES' WHERE userid = %s""", (z, ))

This doesn't do anything though. When I view the accounts table, nothing's changed.


1 Answers

You need to commit the changes after the update:

db.commit()

where db is a database connection instance (the result of connect() call).

Also see: Database does not update automatically with MySQL and Python.

like image 156
alecxe Avatar answered Jun 16 '26 17:06

alecxe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!