首页 MySql数据库开发课程 Python操作MySQL查询数据操作
pay pay

Python操作MySQL查询数据操作

日期: 五月 9, 2023, 5:32 a.m.
阅读: 147
作者: Python自学网-村长

摘要: Python操作MySQL查询数据操作

import pymysql


# 数据库查询操作
# fetchone() 获取下一个查询结果集 ,结果集是一个对象
# fetchall() 接收全部的返回的行
# rowcount   是一个只读属性,返回execute()方法影响的行数
db = pymysql.connect("localhost", "root", "wsw..177122", "wakey")
cursor = db.cursor()

sql = 'select * from bandcard where money>400'

try:
    cursor.execute(sql)
    reslist = cursor.fetchall()
    for row in reslist:
        print("%d--%d" % (row[0], row[1]))  # 打印键值对
except:
    db.rollback()


cursor.close()
db.close()

 

原创视频,版权所有,未经允许,切勿转载,违者必究!
回顶部