Retrieving column values by column name with MySQLdb

Mike Kazantsev mk.fraggod at gmail.com
Fri Jun 19 11:07:11 EDT 2009


On Fri, 19 Jun 2009 15:46:46 +0100
jorma kala <jjkk73 at gmail.com> wrote:

> Is there a way of retrieving the value of columns in the rows returned by
> fetchall, by column name instead of index on the row?

Try this:

  db = MySQLdb.Connection(host=host,user=user,passwd=passwd,db=database)
  db.query(query)
  result = db.store_result()
  data = result.fetch_row(maxrows=0, how=1)

-- 
Mike Kazantsev // fraggod.net
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 205 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20090619/e5e56f83/attachment-0001.sig>


More information about the Python-list mailing list