Files
python----/数据库/本地/测试数据库.ipynb
admin 2d8c1ea8f9 chore: 批量新增各类工具脚本与配置文件
1. 新增音频录制、下载、上传相关脚本
2. 新增数据库操作、API调用工具
3. 新增Excel数据处理脚本
4. 新增弱密码检测脚本
2026-06-14 17:47:15 +08:00

2.8 KiB

In [2]:
# %%
import pymysql

# %%

# 创建数据库连接
connection = pymysql.connect(
host='192.168.0.244',
port=3300,
user='root',
password='hxyd1109',
database='school_server',
charset='utf8'
)
cursor = connection.cursor()
# %%
def create_table(cursor,result):
    
    data = []
    for i in result:
        list_list = list(i)
        des=cursor.description  # 获取表详情,字段名,长度,属性等
        t = ",".join([item[0] for item in des])
        table_head = t.split(',')  # # 查询表列名 用,分割
    
        dict_result = dict(zip(table_head, list_list))  # 打包为元组的列表 再转换为字典
        data.append(dict_result)  # 将字典添加到list_result中
    return data

# %%

# %%

# %%
sql1 = "select * from teacher where id=828"
cursor.execute(sql1)
result=cursor.fetchall()
table_app = create_table(cursor,result)
In [3]:
table_app
Out [3]:
[{'id': 828,
  'tea_name': '彭兰英',
  'sex': 2,
  'phone': '15198039323',
  'type': 6,
  'grade_id': None,
  'class_id': None,
  'user_name': 'ptszxbr9023',
  'team_id': '110',
  'pid': None,
  'serial_no': '1336827486',
  'openid': None,
  'tea_no': 'ptszxbr9023',
  'wx_phone': '15198039323',
  'user_id': None,
  'department_id': None,
  'zt_teacher_uuid': None,
  'hire': '职工',
  'power': '门卫安保',
  'class_type_name': None,
  'hire_id': 98,
  'flag': None,
  'state': 1,
  'sync_source': 'local'}]