python 用字典形式查询mysql数据库
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
import MySQLdb
import MySQLdb.cursors
db = MySQLdb.connect("192.168.101.234", "root", "luca321", "monworks",cursorclass=MySQLdb.cursors.DictCursor)
cursor = db.cursor()
cursor.execute("select id,name from test")
results = cursor.fetchall()
for row in results:
print row["id"]