This method retrieves the next row of a query result set,
returning a single sequence, or None when no
more data is available.The returned tuple consists of data
returned by the MySQL server converted to Python objects.
The fetchone() method is used by
fetchmany()
and
fetchall().
It is also used when using the MySQLCursor
instance as an iterator.
The following examples show how to iterate through the result of
a query using fetchone():
# Using a while-loop
cursor.execute("SELECT * FROM employees")
row = cursor.fetchone()
while row is not None:
print(row)
row = cursor.fetchone()
# Using the cursor as iterator
cursor.execute("SELECT * FROM employees")
for row in cursor:
print(row)Note that you must fetch all rows before being able to execute new queries using the same connection.

User Comments
Add your own comment.