Read the database pymysql

# Read the database

    # Link database 
# Create a query page
# input sql statement to
query #
# view the results
# close the query page
# close the database

import pymysql

class ReadMysql:
def __init__(self):
self.mysql = pymysql.connect(host='', user='', password='', charset='utf8', port=3306)
self.cursor = self.mysql.cursor()

def fetch_one(self, sql):
self.cursor.execute(sql)
result = self.cursor.fetchone()[0]
print(result)

def fetch_all(self, sql):
self.cursor.execute(sql)
result = self.cursor.fetchall()[0][0]
print(result)


def close(self):
self.cursor.close()
self.mysql.close()


if __name__ == '__main__':




Guess you like

Origin www.cnblogs.com/sophia-985935365/p/12634467.html