python数据库向列添加+1

zour9fqk  于 2021-07-26  发布在  Java
关注(0)|答案(1)|浏览(357)

我想在我的数据库中增加一列,我该怎么做?

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

如果有人能帮我,谢谢你的帮助!

li9yvcax

li9yvcax1#

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

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

这个 ? 在查询中应替换为 id 谁的那一排 nb_win 你想增加。

相关问题