python3.5 mysql helper

#!/usr/bin/python
# -*- coding: UTF-8 -*-

import pymysql


def get_connection():
    url = "127.0.0.1"
    database = "analyzer"
    user = "root"
    password = "toor"
    charset = "utf8"
    return pymysql.connect(host=url, port=3306, user=user, passwd=password, db=database, charset=charset)


class MysqlHelper:

    def query(self, sql):
        conn = get_connection()
        cursor = conn.cursor()
        cursor.execute(sql)
        result = cursor.fetchall()
        cursor.close()
        conn.close()
        return result

猜你喜欢

转载自blog.csdn.net/ecjtusanhu/article/details/102461659