代码拉取完成,页面将自动刷新
"""
删除数据
"""
import MySQLdb
no = int(input('编号:'))
# 1. 创建连接对象
conn = MySQLdb.connect(host='47.104.31.138', port=3306,
user='root', password='Luohao.618',
database='hrs', charset='utf8')
try:
# 2. 获取游标对象
with conn.cursor() as cursor:
# 3. 通过游标对象向数据库发出SQL语句获取执行结果
affected_rows = cursor.execute(
'delete from tb_dept where dno=%s',
(no, )
)
if affected_rows == 1:
print('删除部门成功')
# 4. 提交事务
conn.commit()
except MySQLdb.MySQLError as err:
print(err)
# 4. 回滚事务
conn.rollback()
finally:
# 5. 关闭数据库连接(释放资源)
conn.close()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。