Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm using MySQLdb in python to connect to a mysql database (duh) and am really missing the functionality that's built into PHP, namely:

mysql_fetch_array and mysql_fetch_object

What is the equivalent in Python so that I can start getting my scripts ported?

share|improve this question
First result of googling (is this officially a verb now!?) "python mysql" - mysql-python.sourceforge.net - is a DBAPI 2.0 compliant interface, so .fetch() and .fetchall() on cursor objects... – Jon Clements Jul 24 '12 at 9:37
I ask this because perhaps there's a "specific way" that everyone's doing it and that's why I'm the only one pulling out hair? – smftre Jul 24 '12 at 9:40
As always: mysql_*() is outdated and should be used anymore. Use MySQLi or PDO_MySQL instead. – KingCrunch Jul 24 '12 at 9:48
Not really - Create a connection object, create a cursor, execute a query on the cursor, then iterate over the cursor object and you get the equiv of mysql_fetch_array – Jon Clements Jul 24 '12 at 9:48
So using PDO would probably be that "preferred method" or once not quite? – smftre Jul 24 '12 at 10:06

closed as not a real question by Wooble, casperOne Jul 25 '12 at 12:08

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, see the FAQ.

1 Answer

up vote 0 down vote accepted

What I was looking for was the DictCursor:

cur = con.cursor(MySQLdb.cursors.DictCursor)
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.