To return results as a dictionary or as a tuple, we use the DictCursor to fetch rows.
import MySQLdb
import MySQLdb.cursors
conn = MySQLdb.connect(
host = "localhost",
user = "xxx",
passwd = "xxx",
db = "xxx",
cursorclass = MySQLdb.cursors.DictCursor)
cur = conn.cursor()
cur.execute("select id, address from phonebook where city_id = 0")
data = cur.fetchall()
No comments:
Post a Comment