This method retrieves the next row of a query result set,
returning a single sequence, or
None when no
more rows are available.The returned tuple consists of data
returned by the MySQL server converted to Python objects.
The following example shows how to use
fetchone() to process a query result, first
while loop, then using an iterator:
# 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)
You must fetch all rows before being able to execute new queries using the same connection.