1 import pymysql 2 3 class readMysql(object): 4 def __init__(self): 5 #建立數據庫連接 6 self.db = pymysql.connect(host=IP地址, port=端口號,user=賬號, password=密碼,db =數據庫, charset='utf8') 7 #新建查詢頁面 8 self.cursor = self.db.cursor() 9 10 def get_hidden_list(self): 11 #編寫sql 12 sql = "SELECT COUNT(ID) FROM 表 13 #執行sql 14 self.cursor.execute(sql) 15 #查詢結果 16 resuls = self.cursor.fetchone() 17 for i in resuls: 18 return i 19 20 #關閉sql 21 def clos_sql(self): 22 self.cursor.close() 23 24 #關閉數據庫 25 def clos_mysql(self): 26 self.db.close()