-3

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?

5
  • 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... Commented Jul 24, 2012 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? Commented Jul 24, 2012 at 9:40
  • As always: mysql_*() is outdated and should be used anymore. Use MySQLi or PDO_MySQL instead. Commented Jul 24, 2012 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 Commented Jul 24, 2012 at 9:48
  • So using PDO would probably be that "preferred method" or once not quite? Commented Jul 24, 2012 at 10:06

1 Answer 1

0

What I was looking for was the DictCursor:

cur = con.cursor(MySQLdb.cursors.DictCursor)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.