Kiran
Kiran

Reputation: 8528

Cursor.execute does not work in Python

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 ?

Upvotes: 1

Views: 4988

Answers (1)

sinaiy
sinaiy

Reputation: 116

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.

Upvotes: 3

Related Questions