12345678910111213141516171819202122 |
- import pymysql
- class Database:
- def __init__(self, host, user, password, database):
- self.connection = pymysql.connect(
- host=host,
- user=user,
- password=password,
- database=database
- )
- def query(self, sql):
- with self.connection.cursor() as cursor:
- cursor.execute(sql)
- result = cursor.fetchall()
- return result
- def execute(self, sql):
- with self.connection.cursor() as cursor:
- cursor.execute(sql)
- self.connection.commit()
|