その時点でMySQLサーバーバージョン5.1.63を使用していたとき、データベースにデータを保存するためにdb_connection.commit()を使用していませんでした。しかし、使用せずに、MySQLデータベースにデータを保存することもできました。
例:
c = conn.cursor()
# Create table
c.execute('''CREATE TABLE stocks
(date text, trans text, symbol text, qty real, price real)''')
# Insert a row of data
c.execute("INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14)")
この実行後、データはデータベースに更新されます。
ただし、5.5.27 MySQLサーバーのバージョンでは、db_connection.commit()を使用してデータをデータベースに保存する必要があります。
例:c = conn.cursor()
# Create table
c.execute('''CREATE TABLE stocks
(date text, trans text, symbol text, qty real, price real)''')
# Insert a row of data
c.execute("INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14)")
# Save (commit) the changes
conn.commit()
# We can also close the connection if we are done with it.
# Just be sure any changes have been committed or they will be lost.
conn.close()