直接上代码吧
import pymysql import re if __name__ == '__main__': try: # 连接数据库 conn = pymysql.connect(host='阿里云数据库地址', user='账号', password='密码', db='数据库名称', port=端口号(一般为3306,也可以自己设置), charset='utf8') print('连接数据库成功!') cursor = conn.cursor() sql = "select * from pay_info where name='p'" res = cursor.execute(sql) print(res) print(type(res)) data1 = [] data = list(cursor.fetchall()) print(data) for x in data: print(x) data1.extend(x) print(data1) if len(data1) == 0: print('请联系充值') else: conn.close() print('已验证,数据库已经关闭') except Exception as e: print(e)