连接查询
def getEmailAndIdFrom169(sql):
conn = MySQLdb.connect(host="192.168.6.169", user="resume", passwd="zhimakaimen", db="resumedb", charset='utf8')
cur = conn.cursor()
cur.execute('SET NAMES UTF8')
conn.commit()
oper = cur.execute(sql)
data = cur.fetchmany(oper)
cur.close()
return data
插入:
def InsertIntoDB(time,username,step1num,step2num,step2repeatnum,step3num,rukunum,dajienum,yingcainum):
conn = MySQLdb.connect(host="192.168.6.65", user="root", passwd="root", db="filemyftpprocessinfo", charset='utf8')
cur = conn.cursor()
cur.execute('SET NAMES UTF8')
conn.commit()
sql = "insert into usercount_processinfo (time,username,step1num,step2num,step2repeatnum,step3num,mongonum,dajienum,yingcainum) values('%s','%s',%d,%d,%d,%d,%d,%d,%d)"%(time,username,step1num,step2num,step2repeatnum,step3num,rukunum,dajienum,yingcainum)
cur.execute(sql)
conn.commit()
cur.close()
> 更新:
conn = MySQLdb.connect(host="192.168.6.65", user="root", passwd="root", db="emailresume", charset='utf8')
cur = conn.cursor()
cur.execute('SET NAMES UTF8')
conn.commit()
sql_update = "update emailstate set password='%s" % password + "',login='-1'" + " where email='%s" % email + "'"
cur.execute(sql_update)
conn.commit()
cur.close()