小编use*_*306的帖子

Python mySQL更新,工作但不更新表

我有一个需要更新mysql数据库的python脚本,到目前为止:

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<br/>"
   print e  
Run Code Online (Sandbox Code Playgroud)

该脚本Row(s) were updated :使用正确的行数打印,其行数为RadioID11.如果我将其更改RadioID为表中不存在的另一个数字,它将说明Row(s) were updated :0.但是,数据库实际上并未更新.该CurrentState领域保持不变.如果我将SQL语句复制并传递给PHPMyAdmin,它可以正常工作.

python mysql sql-update mysql-connector-python

33
推荐指数
3
解决办法
4万
查看次数