import pymysql
connector = pymysql.connect(host="localhost", port=3306, user="root", password="", database="python", charset="utf8")
cursor = connector.cursor()
print(cursor.execute("show tables;"))
print(cursor.fetchall())
print(cursor.execute("desc class;"))
print(cursor.fetchall())
print(cursor.execute("select * from class;"))
print(cursor.fetchall())
id_ = input("请输入ID:")
parameter = [id_]
print(cursor.execute("select * from class where id=%s;", parameter))
print(cursor.fetchall())
try:
print(cursor.execute("update class set cls='三' where id=3;"))
except:
connector.rollback()
else:
connector.commit()
print(cursor.execute("select * from class ;"))
print(cursor.fetchall())
cursor.close()
connector.close()