123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- """
- Mysql Functions
- """
- import pymysql
- class MysqlClient(object):
- """
- MySQL工具, env默认prod版本
- """
- def __init__(self):
- mysql_config = {
-
- "host": "rr-bp1l12ea7e9wgu947.mysql.rds.aliyuncs.com",
- "port": 3306,
- "user": "wx2016_longvideo",
- "passwd": "wx2016_longvideoP@assword1234",
- "db": "longvideo",
- "charset": "utf8mb4"
- }
- self.connection = pymysql.connect(
- host=mysql_config['host'],
- port=mysql_config['port'],
- user=mysql_config['user'],
- passwd=mysql_config['passwd'],
- db=mysql_config['db'],
- charset=mysql_config['charset']
- )
- def select(self, sql):
- """
- 查询
- :param sql:
- :return:
- """
- cursor = self.connection.cursor()
- cursor.execute(sql)
- data = cursor.fetchall()
- return data
- def update(self, sql):
- """
- 插入
- :param sql:
- :return:
- """
- cursor = self.connection.cursor()
- try:
- res = cursor.execute(sql)
- self.connection.commit()
- return res
- except Exception as e:
- self.connection.rollback()
- def close(self):
- """
- 关闭连接
- """
- self.connection.close()
|