使用python连接mysql数据库时,如果遇到这样的错误提示:
(2014, "Commands out of sync; you can't run this command now")
可能是你的几条sql语句执行顺序有问题,也有可能是cursor本身的bug。
在执行sql语句前最好清空 cursor里面的所有内容。
def executeNonQuery(cursor, sql):
while cursor.nextset(): pass
cursor.execute(sql)
这样就没有问题了
(2014, "Commands out of sync; you can't run this command now")
可能是你的几条sql语句执行顺序有问题,也有可能是cursor本身的bug。
在执行sql语句前最好清空 cursor里面的所有内容。
def executeNonQuery(cursor, sql):
while cursor.nextset(): pass
cursor.execute(sql)
这样就没有问题了
本文介绍了一种在使用Python操作MySQL数据库时遇到的同步问题及其解决方案。主要原因是SQL语句执行顺序不当或cursor存在bug导致。文章提供了一个实用的方法来清空cursor中所有内容,从而避免此类错误。
18万+





