#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()