为了账号安全,请及时绑定邮箱和手机立即绑定

python数据库向列添加+1

python数据库向列添加+1

潇湘沐 2022-12-20 14:04:22
我想在我的数据库中增加一列,我该怎么做?if result[0] is True and result[1] != "":  # a win               your_details["score"] = your_details["score"] + 1               lbl_status["text"] = "Game over, You won! You(" + str(your_details["score"]) + ") - " \                                                                                              "" + opponent_details[                                        "name"] + "(" + str(opponent_details["score"]) + ")"               req = 'UPDATE INTO users("nb_win") VALUES("nb_win + 1")'               infos = your_details["score"]               print(infos)               try:                   cursor.execute(req, infos)                   db_connection.commit()               except mysql.Error as err:                   print(err)def connect():    global your_details    if len(ent_name.get()) < 1:        tk.messagebox.showerror(title="ERROR!!!", message="You MUST enter your first name <e.g. John>")    else:        your_details["name"] = ent_name.get()        print(ent_name.get())        connect_to_server(ent_name.get())        req = 'INSERT INTO users(user_name) VALUES("'+ ent_name.get()+'")'        infos = ent_name     如果有人可以帮助我,谢谢你的帮助!
查看完整描述

1 回答

?
白衣非少年

TA贡献1155条经验 获得超0个赞

你想要一个update声明。假设您的表的主键是id,那将是:

UPDATE users SET nb_win = nb_win + 1 WHERE user_name = ?

查询中的?应替换为您要递增id的行的。nb_win


查看完整回答
反对 回复 2022-12-20
  • 1 回答
  • 0 关注
  • 133 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号