失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > python调用数据库存储过程_python连接mysql调用存储过程示例

python调用数据库存储过程_python连接mysql调用存储过程示例

时间:2021-05-26 21:27:50

相关推荐

python调用数据库存储过程_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调用存储过程示例

本文地址: /shujuku/mysql/106053.html

如果觉得《python调用数据库存储过程_python连接mysql调用存储过程示例》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。