python遍历数据

 #coding=utf-8
import MySQLdb
conn = MySQLdb.Connect(host = '127.0.0.1',port=3306,user='root',passwd='',db='test',charset='utf8')
cursor = conn.cursor()
sql = "select * from orders order by id asc"
cursor.execute(sql) #获取所有数据,遍历所有的数据
rs = cursor.fetchall()
for row in rs:
print "id=%d,order_id=%d,product_id=%d" % row cursor.close()
conn.close()
上一篇:Spring 3.x jar 包详解 与 依赖关系(转)


下一篇:8 个基于 Lucene 的开源搜索引擎推荐