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

yipeiwu_com6年前Python基础

复制代码 代码如下:

#!/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中使用不同编码读写txt文件详解

复制代码 代码如下: import os import codecs filenames=os.listdir(os.getcwd()) out=file("name.txt","w")...

Python常见数据结构之栈与队列用法示例

本文实例讲述了Python常见数据结构之栈与队列用法。分享给大家供大家参考,具体如下: Python常见数据结构之-栈 首先,栈是一种数据结构。具有后进先出特性。 #栈的实现 cla...

Python封装shell命令实例分析

本文实例讲述了Python封装shell命令的方法。分享给大家供大家参考。具体实现方法如下: # -*- coding: utf-8 -*- import os import sub...

python GUI图形化编程wxpython的使用

python GUI图形化编程wxpython的使用

一、python gui(图形化)模块介绍:   Tkinter :是python最简单的图形化模块,总共只有14种组建   Pyqt :是python最复杂也是使用最广泛的图形化   ...

python中defaultdict的用法详解

初识defaultdict 之前在使用字典的时候, 用的比较随意, 只是简单的使用dict. 然而这样在使用不存在的key的时候发生KeyError这样的一个报错, 这时候就该defa...