当我在我的覆盆子-pi中运行此代码时,没有任何事情发生,代码运行得很顺利,但没有结果
#!/usr/bin/python
import MySQLdb
db = MySQLdb.connect(host="localhost", # your host, usually localhost
user="root", # your username
passwd="raspberry", # your password
db="raspberry") # name of the data base
cur = db.cursor()
cur.execute("UPDATE visitors SET nb_visits = nb_visits+1 WHERE id = 1")
答案 0 :(得分:0)
在更改生效之前,您应该commit您的交易:
cur.execute("UPDATE visitors SET nb_visits = nb_visits+1 WHERE id = 1")
db.commit()