gpt4 book ai didi

Python mysqldb 返回插入的行,但 mysql 返回一个空集

转载 作者:太空宇宙 更新时间:2023-11-03 10:21:44 24 4
gpt4 key购买 nike

我使用 mysqldb 插入一行:

 def insertNewLog(self,uid,beginDate,endDate,logs):
qry1 = """INSERT INTO logs (owner,createDate,endDate,log) VALUES (%s,%s,%s,%s); """
cursor = self.db.cursor()
beginDate = int(time.mktime( beginDate.timetuple() ))
endDate = int(time.mktime( endDate.timetuple()))
print beginDate
print endDate
cursor.execute(qry1,(uid,beginDate,endDate,logs),)
print "inserted normally"
print "Number of rows inserted: %d" % cursor.rowcount

我得到这个输出:

1337720045
1337740625
inserted normally
Number of rows inserted: 1

然而,当我在 mysql shell 中对我的数据库进行选择时,我得到“空集”。我检查了我的 mysql 日志,里面没有任何报告。我有点困惑。

最佳答案

您应该在您的数据库连接上调用 commit()。否则插入将回滚。

关于Python mysqldb 返回插入的行,但 mysql 返回一个空集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10659635/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com