Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python mysql连接器Fetchone返回none_Python_Mysql_Python 3.x_Mysql Python - Fatal编程技术网

python mysql连接器Fetchone返回none

python mysql连接器Fetchone返回none,python,mysql,python-3.x,mysql-python,Python,Mysql,Python 3.x,Mysql Python,我正在尝试使用Python mysql连接器连接mysql 这是密码 from mysql.connector import connect as mysqlConnect, Error myConn = mysqlConnect(host=host, database=database, user=user, password=password, port=port) if myConn.is_connected(): print('Connected to MySQL databa

我正在尝试使用Python mysql连接器连接mysql

这是密码

from mysql.connector import connect as mysqlConnect, Error

myConn = mysqlConnect(host=host, database=database, user=user, password=password, port=port)
if myConn.is_connected():
    print('Connected to MySQL database')

cursor = myConn.cursor()
cursor.execute(query)
print(cursor.rowcount)
row = cursor.fetchone()
....
问题是,即使cursor.rowcount为3,cursor.fetchone()也不会返回任何值

请帮我找出我在这里做错了什么

您的代码必须是:

from mysql.connector import connect as mysqlConnect, Error

myConn = mysqlConnect(host=host, database=database, user=user, password=password, port=port)
if myConn.is_connected():
    print('Connected to MySQL database')

cursor = myConn.cursor()
cursor.execute(query)
print(cursor.rowcount)
cursor.execute(query)
row = cursor.fetchone()
....
我添加了一个
游标。执行(查询)
行以再次运行查询。从光标获取
行数
或其他数据时,如果相同,则必须再次运行查询事件。

您的代码必须是:

from mysql.connector import connect as mysqlConnect, Error

myConn = mysqlConnect(host=host, database=database, user=user, password=password, port=port)
if myConn.is_connected():
    print('Connected to MySQL database')

cursor = myConn.cursor()
cursor.execute(query)
print(cursor.rowcount)
cursor.execute(query)
row = cursor.fetchone()
....

我添加了一个
游标。执行(查询)
行以再次运行查询。当您从游标获取
行计数
或其他数据时,如果相同,则必须再次运行查询事件。

通过执行
游标。行计数
您可能已经耗尽了迭代器。只需删除行
print(cursor.rowcount)
,看看会发生什么。这是后来添加的,只是为了检查。如果没有这个,它就不能工作。我的答案有用吗@mry通过执行
cursor.rowcount
您可能已经耗尽了迭代器。只需删除行
print(cursor.rowcount)
,看看会发生什么。这是后来添加的,只是为了检查。如果没有这个,它就不能工作。我的答案有用吗@问题代码不起作用和你的有什么区别?你没有解释任何事情我添加了一个游标。执行(查询)再次运行查询。测试它并告诉我它是否有效。我认为接受我的答案并投票会很好。当你从光标获取数据时,除非你再次运行查询,否则你无法再次获取数据。不起作用的问题代码和你的问题代码之间的区别在哪里?你没有解释任何事情我添加了一个游标。执行(查询)再次运行查询。测试它并告诉我它是否有效。我认为接受我的答案并投赞成票是很好的。当你从光标获取数据时,除非你再次运行查询,否则你无法再次获取数据。