源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2021-06-02 16:01 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:python连接mysql调用存储过程示例
[u]复制代码[/u] 代码如下:
#!/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
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部