import pymysql #创建连接 con = pymysql.connect(host='localhost',user='root',password='123456',port=3306,database='zhy') #创建游标对象 cur = con.curson() #编写查询的sql语句 sql = 'select * from t_student' try: cur.execute(sql) print("查询成功") students = cur.fetchall() print(students) except Exception as e: print(e) print("查询失败") finally: cur.close() con.close()
报错:AttributeError: 'Connection' object has no attribute 'curson'
检查一遍发现马虎了,应该是con.cursor()