Pyqt5学习笔记六、PYQT5数据库使用

磊落不羁 by:磊落不羁 分类:pyQt5 时间:3年前 阅读:131 评论:0

六、PYQT5 Mysql 数据库使用

1、安装PyMySQL模块

pip install PyMySQL

2、数据库使用流程

import pymysql
#1、链接数据库
db=pymysql.connect("localhost",'root','123456','mrsoft')
# 2、获取游标
cursor=db.cursor()
# 3.执行sql查询
cursor.execute("select * from `student` where id=3;")
# 4.获取结果
res=cursor.fetchall()

# 5。关闭游标和链接
cursor.close()
db.close()

3、创建数据库

image-20221223114315124

4、操作MySQL数据表

插入数据时,可以使用excute()方法添加一条记录,也可以使用executemany()方法批量添加多条记录。

image-20221223114441156

非特殊说明,本文版权归原作者所有,转载请注明出处

本文地址:http://php.liulei.com.cn/?type=acticle&id=71

评论列表

发表评论

  • 昵称(必填)
  • 邮箱
  • 网址

TOP