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()