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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

  2021-03-19 我要评论
想了解python连接mysql调用存储过程示例的相关内容吗,在本文为您仔细讲解python连接mysql的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点: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

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们