python连接mysql调用存储过程示例

请好好珍惜,因为今天是你往后日子里最年轻的一天。有了梦想,你就会有动力,有了动力,你才会有成功的希望。对待健康,偏见比无知更可怕!


#!/usr/bin/env python
# -*- coding: utf8 -*-
import MySQLdb
import time
import os, sys, string
def CallProc(id,onlinetime):
'''调用存储过程,
输入参数:编号,在线时间,输出:帐号,密码;
使用输出参数方式'''
accname=''
accpwd=''
conn = MySQLdb.connect(host='localhost',user='root',passwd='111111',db='ceshi')
cur =conn.cursor()
cur.callproc('proctest',(id,onlinetime,accname,accpwd))
cur.execute('select @_proctest_2,@_proctest_3')
data=cur.fetchall()
if data:
for rec in data:
accname=rec[0]
accpwd=rec[1]
cur.close()
conn.close();
return accname,accpwd
def CallProct(id,onlinetime):
'''调用存储过程,
输入参数:编号,在线时间,输出:帐号,密码;
使用select返回记录方式'''
accname=''
accpwd=''
conn = MySQLdb.connect(host='localhost',user='root',passwd='111111',db='ceshi')
cur =conn.cursor()
cur.nextset()
cur.execute('call ptest(%s,%s)',(id,onlinetime))
data=cur.fetchall()
if data:
for rec in data:
accname=rec[0]
accpwd=rec[1]
cur.close()
conn.close();
return accname,accpwd
name,pwd=CallProct(1,0)
print name,pwd

以上就是python连接mysql调用存储过程示例。向后看才能理解生活;但要生活好,则必须向前看。更多关于python连接mysql调用存储过程示例请关注haodaima.com其它相关文章!

标签: 存储过程 python