Python3.0 operations MySQL database query execution

# coding: utf-8 
import pymysql

class MysqldbHelper(object):
def __init__(self, host="192.168.1.243", username="devlop", password="devlop", port=3306, database='zl_dcms', charset='utf8'):
    self.host = host
    self.username = username
    self.password = password
    self.database = database
    self.port = port
   self.con = None
    self.cur = None
    self.charset = charset
    try:
      self.con = pymysql.connect(host=self.host, user=self.username, The passwd = self.password , Port = self.port , DB = self.database)
      # all queries are run in a block cursor connection con above       self.cur = self.con.cursor () the except:       Print ( . "DataBase Connect error, the Check Please at The db config") DEF the Find (Self , SQL):     SQL = SQL the try:       self.cur.execute (SQL)       Results = self.cur.fetchall () for Row in Results:         Print ( '% S' Row%) return ( '% S' Row%)     the except pymysql.Error AS E:       error = '! Execute the MySQL failed eRROR (% S): S%'% (e.args [ 0] , E. args [ . 1]) Print (error)

    




    


      

        

Guess you like

Origin www.cnblogs.com/xioawu-blog/p/11005321.html