我在Python中使用MySQLdb
包来更新我的数据库。我有一个简单的更新命令如下:
update_query = "update user_details set `address`='%s' where `id`='%s'"
cursor.execute(update_query, (address, id1))
print(cursor._last_executed)
这是执行的命令:
update user_details set `address`='35, Chikmagalur' where `id`='242069'
程序运行正常,没有错误。但是,数据库没有得到更新。当我在PHPMyAdmin上作为SQL查询运行时,相同的命令有效。
知道可能是什么问题吗?
答案 0 :(得分:1)
这是......的复制品。
需要显式或隐式地提交sql事务。
显式发出提交命令 cursor._get_db()。提交()
打开连接时将连接设置为自动提交也是一种选择。