我要选择和插入多个查询。为了顺序运行多个选择查询时,为了避免连接丢失,我使用connection.refresh() 例如,依次查询10个查询,在第5个查询中,我得到的是元组而不是字典。
connection = pymysql.connect(host='localhost',user='user',password='passwd',db='db',charset='utf8mb4',cursorclass=pymysql.cursors.DictCursor)
connection.commit()
cur = connection.cursor()
sql = "SELECT `id`, `password` FROM `users` WHERE `email`=%s"
cursor.execute(sql, ('webmaster@python.org',))
result = cursor.fetchone()
print(result)
connection = connection.refresh()
cur = connection.cursor()
sql = "SELECT `id`, `password` FROM `users` WHERE `email`=%s"
cursor.execute(sql, ('webmaster@python.org',))
result = cursor.fetchone()
print(result) //Returns tuple instead of DIct
有人遇到过这样的错误吗?