Implementation of the Python operation MySQL database

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.