我正在尝试从AWS MariaDB获取数据:cursor = self._cnx.cursor()
stmt = ('SELECT * FROM flights')
cursor.execute(stmt)
print(cursor.rowcount)
# prints 2
for z in cursor:
print(z)
# Does not iterate
row = cursor.fetchone()
# row is None
rows = cursor.fetchall()
# throws 'No result set to fetch from.'
我可以使用MySQL Workbench验证表是否包含数据。我是不是错过了一步?在
编辑:回复2答案:
^{pr2}$
编辑:
我用一个文件创建了一个新的Python项目:import mysql.connector
try:
cnx = mysql.connector.connect(
host='foobar.rds.amazonaws.com',
user='devuser',
password='devpasswd',
database='devdb'
)
cursor = cnx.cursor()
#cursor = cnx.cursor(buffered=True)
cursor.execute('SELECT * FROM flights')
print(cursor.rowcount)
rows = cursor.fetchall()
except Exception as exc:
print(exc)
如果我用简单的游标运行这段代码,fetchall会引发“No result set to fetch from”。如果我使用缓冲游标运行,我可以看到cursor的\u rows属性包含我的数据,但是fetchall()返回空数组。在