Getting a Cursor in MySQL Python

In order to put our new connnection to good use we need to create a cursor object. The cursor object is an abstraction specified in the Python DB-API 2.0. It gives us the ability to have multiple seperate working environments through the same connection to the database. You can create a cursor by executing the 'cursor' function of your database object.

		cur = db.cursor()

By default the cursor is created using the default cursor class. If you like you can specify a different cursor class by setting the 'cursorclass' parameter to the cursor class you would like to use. There are several different cursor classes that give you different functionality when executing queries.

An example of this is using the DictCursor to have your results returned to you as Python dictionaries instead of the default which is a Python list. For more information on the available cursor classes check the reference section.

<-- Home -->