mysql.connector multiple queries: Error -1: No result set to fetch from

烂漫一生 提交于 2019-12-25 08:57:20

问题


In Python 2.7.3, Wins 10, MySQL remote server 5.6.23, MySQL.connector 2.1.3,

If I wanna run these two queries together in Python MySQL.connector:

SELECT * FROM A LIMIT 5;


SELECT DISTINCT COLUM_A FROM B;

I got the following error message using the code below:

Error -1: No result set to fetch from.

Here is the code:

import mysql.connector as MySQL

cursor = conn.cursor ()

sql1 = "SELECT * FROM A LIMIT 5;SELECT DISTINCT COLUM_A FROM B"

cursor.execute(sql1,multi=True)

row = cursor.fetchall ()

warning = cursor.fetchwarnings()

print row

print warning

cursor.close ()

conn.close ()

Here is the MySQL cursor.execute() official document, which completely confuses me. Could any guru enlighten? Thanks!

https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlcursor-execute.html


回答1:


Change the code to-

iterable = cursor.execute(sql1,multi=True)
for item in iterable:
    print(item.fetchall())

Should work.



来源:https://stackoverflow.com/questions/37665993/mysql-connector-multiple-queries-error-1-no-result-set-to-fetch-from

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!