2、实现代码如下:#!/usr/bin/env python
# encoding: utf-8
import MySQLdb
# 数据操作类
class DBHelper:
"""
数据操作类,提供数据操作的方法
"""
def __init__(self, host, user, password, port, database):
self.host = host
self.user = user
self.port = port
self.password = password
self.database = database
def call_procedure(self, procedure_name, tuple_parameters):
"""
procedure_name: 被调用的存储过程
tuple_parameters: 使用的参数
返回结果:
"""
try:
conn = MySQLdb.connect(host=self.host,
user=self.user,
passwd=self.password,
port=self.port,
db=self.database)
conn.autocommit(True)
cur = conn.cursor()
cur.callproc(procedure_name, tuple_parameters)
data = cur.fetchall()
cur.close()
conn.close()
return data
except MySQLdb.Error, e:
print "存储过程执行出错: %d: %s" % (e.args[0], e.args[1])
return None