当前位置: 移动技术网 > IT编程>脚本编程>Python > python连接mysql调用存储过程示例

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

2019年04月01日  | 移动技术网IT编程  | 我要评论

香菇出口,世纪星城,色鹿鹿

复制代码 代码如下:

#!/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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网