1

I have this program in Python:

import pymysql

conn = pymysql.connect(<stuff here>)
cur = conn.cursor()

cur.execute('''
    INSERT INTO aderenti (nome, comune, provincia)
    VALUES ('Mario', 'Spinea', 'VE');
    ''')

the code runs fine, and if I run the SQL command in MySQL workbench a new row appears with the selected values. But if I run this code in Python, no new row appears. How is this possible?

3
  • 2
    You need to call conn.commit(). Commented Dec 1, 2016 at 18:04
  • Thanks a lot, I will try it right now. Thogh I have previously added rows with Python without using conn.commit(), and it worked. So when do I have to use it and when I don't? Commented Dec 1, 2016 at 18:09
  • Use it to commit the transaction Commented Dec 1, 2016 at 18:11

1 Answer 1

2

You already got the answer. as a side note include

autocommit=True

in your connection. It's just easy to have in connection.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.