1, need to use the module MySQLdb, for: http://sourceforge.net/projects/mysql-python/
2, the implementation code is as follows:
#!/usr/bin/env python# encoding: utf-8import mysqldb# Data Manipulation Class class dbhelper: "" data manipulation classes, providing methods for data manipulation "" 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: stored procedures that are called tuple_parameters: parameters used by return results: "" " 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 "Stored Procedure execution error: %d: %s" % (e.args[0], e.args[1]) return none
This article from "Xu Big Tree" blog, declined reprint!
Implementation of the Python operation MySQL database