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报什么错,用这个模块就能正常运行

不管你的Python报什么错,用这个模块就能正常运行

Fucklt.py 使用了最先进的技术能够使你的代码不管里面有什么样的错误,你只管 FuckIt,程序就能"正常"执行,兵来将挡水来土掩。 是不是感觉很不讲道理,这样还担心自己的代码不能...

python基于K-means聚类算法的图像分割

python基于K-means聚类算法的图像分割

1 K-means算法 实际上,无论是从算法思想,还是具体实现上,K-means算法是一种很简单的算法。它属于无监督分类,通过按照一定的方式度量样本之间的相似度,通过迭代更新聚类中心,...

python list元素为tuple时的排序方法

如下所示: dist = [('m',5),('e',4),('c',9),('d',1)] dist.sort(key= operator.itemgetter(0)) print...

python自定义线程池控制线程数量的示例

1.自定义线程池 import threading import Queue import time queue = Queue.Queue() def put_data...

Python入门之三角函数tan()函数实例详解

描述 tan() 返回x弧度的正弦值。 语法 以下是 tan() 方法的语法: import math math.tan(x) 注意:tan()是不能直接访问的,需要导入 m...