#!/usr/bin/env python#encoding:utf-8import mysqldbtell_file= '/home/test/liyiliang/study/tell.info ' F = file (Tell_file) account_list = f.readlines () f.close () For n in account_ List: h=n.strip (). Split () name = h[0] phone = h[1] try: conn = mysqldb.connect (host= ' x.x.x.x ', user= ' xxxx ', passwd= ' xxxxxxx ' , port=xxxxx,charset= ' UTF8 ') cur = conn.cursor () Cur.execute (' select promotioncode from cinf_db.cinf_promotioncode where mp = %s ', phone) mycode = cur.fetchall () numtwo=0 for code in mycode: cur.execute (' Select mp from cinf_db.cinf_promotioncode_reward_history where reward_type=1 and promotioncode = %S ', Code) op = cur.fetchall () Cur.execute (' select count (*) from cinf_db.cinf_promotioncode_reward_history where reward_type=1 and promotioncode= %s ', code) mynum = cur.fetchall () for opnum in op: cur.execute (' Select promotioncode from cinf_db.cinf_promotioncode where mp = %s ', opnum) othercode = cur.fetchall () for oc in othercode: cur.execute (' select count (*) from cinf_db.cinf_promotioncode_reward_history where reward_type=1 and promotioncode = %s ', OC)   &NBSp; everone = cur.fetchall () for a in everone: b=int (a[0]) numtwo += b for numone in mynum: print '%s ' %name, print '%s ' %phone, print '%s ' %numOne, print '%s ' %numTwo Cur.close () conn.close () except MySQLdb.Error,e: print "Mysqldb&nbsP Error ", E
This article from "Chocolee" blog, declined reprint!
Collect departmental staff two times recommended Python script--reference