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.

37 lines
1.0 KiB

6 months ago
import csv
import mysql.connector
from tkinter import messagebox
def dis_collec(user,data_index):
id=''
6 months ago
with open('collections/{}.csv'.format(user), 'r', encoding='utf-8', newline='') as file:
6 months ago
reader = csv.reader(file)
index=0
for row in reader:
if index == data_index:
id=row[0]
6 months ago
break
6 months ago
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('提示','取消收藏成功!')