python pymysql 基本使用

匿名 (未验证) 提交于 2019-12-02 22:02:20
 1 from pymysql import *  2   3 # 1.创建连接数据库  4 conn = connect(host="localhost", port=3306, user="root", password="root", database="jiang_test", charset="utf8")  5 # 2.获取游标  6 cur = conn.cursor()  7 # 数据库操作  8 count = cur.execute("select *from students")  9 res = cur.fetchall()  # fetchone()获取一条数据    fetchmany(n)获取指定n条数据量 10 print(type(res))  # tulpe 11 print(count)  # 打印出查询数据数量 12 print(res)  # 打印出查询数据 13 # 3.关闭游标 14 cur.close() 15 # 4.关闭连接 16 conn.close()

步骤

1.创建连接数据库2.获取游标
3.数据库操作(增删改查)4.关闭游标5.关闭连接

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!