1 Star 0 Fork 19

小春/Python_Learning

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
delete.py 504 Bytes
一键复制 编辑 原始数据 按行查看 历史
阿基米东 提交于 2020-09-10 20:44 +08:00 . pymysql
import pymysql
# 打开数据库连接
db = pymysql.connect(host="localhost",user="root",password="",db="test",charset="utf8")
# 使用 cursor() 方法创建一个游标对象 cursor
cursor = db.cursor()
# 定义删除 sql 语句
sql = "DELETE FROM USER WHERE id = %d"%(20190002)
try:
cursor.execute(sql)
print("成功删除条数:", cursor.rowcount)
db.commit()
except Exception as err:
db.rollback()
print("SQL执行错误,原因:",err)
# 关闭数据库连接
db.close()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/wython/Python_Learning.git
git@gitee.com:wython/Python_Learning.git
wython
Python_Learning
Python_Learning
master

搜索帮助