python mysql update,Python mySQL更新,正在工作但未更新表

博主在尝试使用Python脚本更新MySQL数据库时遇到问题,虽然脚本显示已成功更新指定ID的记录,但实际上数据库并未真正更新。问题在于缺少提交(commit)操作。在执行更新语句后加入`dbb.commit()`,即可确保更改被保存到数据库中。
摘要由CSDN通过智能技术生成

I have a python script which needs to update a mysql database, I have so far:

dbb = MySQLdb.connect(host="localhost",

user="user",

passwd="pass",

db="database")

try:

curb = dbb.cursor()

curb.execute ("UPDATE RadioGroups SET CurrentState=1 WHERE RadioID=11")

print "Row(s) were updated :" + str(curb.rowcount)

curb.close()

except MySQLdb.Error, e:

print "query failed
"

print e

The script prints Row(s) were updated : with the correct number of rows which have a RadioID of 11. If I change the RadioID to another number not present in the table it will say Row(s) were updated :0. However the database doesn't actually update. The CurrentState field just stays the same. If I copy and past the SQL statement in to PHPMyAdmin it works fine.

解决方案

use

dbb.commit()

after

curb.execute ("UPDATE RadioGroups SET CurrentState=1 WHERE RadioID=11")

to commit all the changes that you 'loaded' into the mysql server

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值