diff --git a/pythonProject/.idea/dataSources.xml b/pythonProject/.idea/dataSources.xml new file mode 100644 index 0000000..208626a --- /dev/null +++ b/pythonProject/.idea/dataSources.xml @@ -0,0 +1,12 @@ + + + + + mysql.8 + true + com.mysql.cj.jdbc.Driver + jdbc:mysql://localhost:3306/sys + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/pythonProject/foot_spa.db b/pythonProject/foot_spa.db new file mode 100644 index 0000000..f5c647b Binary files /dev/null and b/pythonProject/foot_spa.db differ diff --git a/pythonProject/user_data.txt b/pythonProject/user_data.txt index a4352ff..1b5d237 100644 --- a/pythonProject/user_data.txt +++ b/pythonProject/user_data.txt @@ -1,3 +1,2 @@ zs,zs - diff --git a/pythonProject/zs1.py b/pythonProject/zs1.py index f896557..c61df69 100644 --- a/pythonProject/zs1.py +++ b/pythonProject/zs1.py @@ -1,6 +1,45 @@ import tkinter as tk from tkinter import messagebox - +import pymysql + +# 数据库连接配置 +host = 'localhost' +user = 'root' +password = '123456' +db = 'sys' + +try: + # 尝试连接数据库 + conn = pymysql.connect(host=host, user=user, password=password, db=db) + print("数据库连接成功") + + # 创建一个Cursor对象 + cursor = conn.cursor() + + # 定义创建用户表的SQL语句 + create_table_sql = """ + CREATE TABLE IF NOT EXISTS users ( + user_id INT AUTO_INCREMENT PRIMARY KEY, + username VARCHAR(255) NOT NULL UNIQUE, + password VARCHAR(255) NOT NULL + ) + """ + + # 执行SQL语句创建表 + cursor.execute(create_table_sql) + print("用户表创建成功") + + # 提交事务 + conn.commit() + +except pymysql.MySQLError as e: + print(f"数据库操作出错: {e}") +finally: + # 关闭Cursor和Connection + if cursor: + cursor.close() + if conn: + conn.close() class FootSpaManagementSystem: def __init__(self,order_info=""):