标签:__init__ data use 连接 运行 cms def pytho etc
# 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, passwd=self.password, port=self.port, db=self.database)
# 所有的查询,都在连接 con 的一个模块 cursor 上面运行的
self.cur = self.con.cursor()
except:
print("DataBase connect error,please check the db config.")
def find(self, sql):
sql = sql
try:
self.cur.execute(sql)
results = self.cur.fetchall()
for row in results:
print(‘%s‘ % row)
return(‘%s‘ % row)
except pymysql.Error as e:
error = ‘MySQL execute failed! ERROR (%s): %s‘ % (e.args[0], e.args[1]) print(error)
标签:__init__ data use 连接 运行 cms def pytho etc
原文地址:https://www.cnblogs.com/xioawu-blog/p/11005321.html