Name

fetchone( )

Signature

                        row = cursor.fetchone(  )

Synopsis

Fetches the next row of a result set returned by a query as a single sequence. This method will return None when no more results exist. It will throw an error if the SQL executed is not a query.

Example

connection = MySQLdb.connect(host='carthage', user='test', 
                             passwd='test', db='test');
cursor = connection.cursor(  );
cursor.execute("SELECT * FROM TNAME");
row = cursor.fetchone(  );
print "Key: ", row[0];
print "Value: ", row[1];

Get Managing & Using MySQL, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.