1

I am using MySQLdb package in Python to update my database. I have a simple update command as follows :

update_query = "update user_details set `address`='%s' where `id`='%s'"
cursor.execute(update_query, (address, id1))
print(cursor._last_executed)

Here is the command executed :

update user_details set `address`='35, Chikmagalur' where `id`='242069'

The program runs fine without error. However, the database is not getting updated. The same command works when I run as an SQL query on PHPMyAdmin.

Any idea what could be the issue ?

1 Answer 1

3

this is a duplicate of ...

sql transactions needs to be committed, either explicitly or implicitly.

either issue a commit command explicitly cursor._get_db().commit()

setting the connection to autocommit when opening the connection is also an option.

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

5 Comments

I have enabled autocommit. Here is the code : db = MySQLdb.connect(host=host, port=port, user=username, passwd=password, db=database, cursorclass=MySQLdb.cursors.DictCursor) db.autocommit = True cursor = db.cursor() But it doesnt work either
you can see the number of effected rows, print(cursor.execute(update_query, (address, id1)))
It says 1 ( 1 row is affected ). However there is no change in the table whasover. Strange
@kiran: check if the db you are checking in is same as the one used in the code
cursor._get_db().commit() worked. However autocommit was enabled to true. Thanks @sinaiy for the help

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.