Python: 练习 PyMySQLPython: 练习 PyMySQLPython: 练习 PyMySQLPython: 练习 PyMySQL
  • 首页
  • 博客
  • 文件
  • 书签
  • 分析
  • 登录
Search
Generic filters

Python: 练习 PyMySQL

Published by admin at 2022年6月19日
Categories
  • Practice
Tags
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()

发表回复 取消回复

您的电子邮箱地址不会被公开。 必填项已用*标注

Categories

  • 猫
  • Python
  • MySQL
  • Django
  • Html/CSS
  • JavaScript
  • Vue
  • RegExp
  • php
  • Practice
  • Virtualization
  • Linux
  • Windows
  • Android
  • NAS
  • Software
  • Hardware
  • Network
  • Router
  • Office
  • WordPress
  • SEO
  • English
  • Games
  • Recipes
  • living
  • Memorandum
  • Essays
  • 未分类

归档

©2015-2022 Alaica Blog support@alaica.com