mysql.connector多个查询:错误-1:未设置要从中获取的结果 [英] mysql.connector multiple queries: Error -1: No result set to fetch from
本文介绍了mysql.connector多个查询:错误-1:未设置要从中获取的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Python 2.7.3中,Wins 10,MySQL远程服务器5.6.23,MySQL.connector 2.1.3,
In Python 2.7.3, Wins 10, MySQL remote server 5.6.23, MySQL.connector 2.1.3,
如果我想在Python MySQL.connector中一起运行这两个查询:
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.
这是代码:
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 ()
这是MySQL cursor.execute()官方文件,这完全使我感到困惑.上师能开导吗?谢谢!
Here is the MySQL cursor.execute() official document, which completely confuses me. Could any guru enlighten? Thanks!
https://dev. mysql.com/doc/connector-python/zh-CN/connector-python-api-mysqlcursor-execute.html
推荐答案
将代码更改为-
iterable = cursor.execute(sql1,multi=True)
for item in iterable:
print(item.fetchall())
应该工作.
这篇关于mysql.connector多个查询:错误-1:未设置要从中获取的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文