You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import csv
import mysql.connector
from tkinter import messagebox
def dis_collec(user,data_index):
id=''
with open('TrialRecommend/data.csv', 'r', encoding='utf-8', newline='') as file:
reader = csv.reader(file)
index=0
for row in reader:
if index == data_index:
id=row[0]
index=index+1
db = mysql.connector.connect(
host="localhost",
user="root",
passwd="A121023020309a",
database="trial"
)
sql='DELETE FROM collections WHERE user_id = %s AND essay_id = %s'
cursor=db.cursor()
success='true'
try:
cursor.execute(sql, (user, id))
db.commit()
except db.Error as e:
print(f"An error occurred: {e}")
db.rollback()
messagebox.showinfo("Error", "取消收藏失败!")
success='false'
finally:
# 确保cursor关闭释放资源
cursor.close()
if success == 'true':
messagebox.showinfo('提示','取消收藏成功!')