"""
@author: luojunhui
"""
import pymysql


class DeNetMysql(object):
    """
     Mysql Server
    """
    connection = pymysql.connect(
        host="rm-t4na9qj85v7790tf84o.mysql.singapore.rds.aliyuncs.com",  # 数据库IP地址，内网地址
        port=3306,  # 端口号
        user="crawler_admin",  # mysql用户名
        passwd="cyber#crawler_2023",  # mysql用户登录密码
        db="aigc-admin-prod",  # 数据库名
        charset="utf8mb4"  # 如果数据库里面的文本是utf8编码的，charset指定是utf8
    )

    @classmethod
    def update(cls, sql, params):
        """
        :param sql:
        :param params:
        :return:
        """
        cursor = cls.connection.cursor()
        affect_rows = cursor.execute(sql, params)
        cls.connection.commit()
        return affect_rows

    @classmethod
    def select(cls, sql):
        """
        查询方法
        :param sql:
        :return:
        """
        cursor = cls.connection.cursor()
        cursor.execute(sql)
        result = cursor.fetchall()
        return result