3
>>> 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.

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195

1 Answers1

3

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.

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • sunnuva! I always forget that.. thank you so much sorry for this ignorant post –  Jun 25 '14 at 14:08
  • @user262064 You might want to create your cursor like `with connection as cursor:` immediately above the `for` loop. Then it will automatically `commit()` on success or `rollback()` on error. – glglgl Jun 25 '14 at 15:46