# import csv
# import pymysql

# # MySQL 연결 설정
# conn = pymysql.connect(
#     host='localhost',
#     user='air',
#     password='Sapporo2025AirPJT!@',  # 위에서 설정한 비밀번호 입력
#     database='AIR',
#     charset='utf8mb4'
# )

# cursor = conn.cursor()

# # CSV 파일 읽기 (헤더 없음)
# csv_file_path = 'data05.csv'  # CSV 파일 경로 설정
# with open(csv_file_path, newline='', encoding='utf-8') as csvfile:
#     reader = csv.reader(csvfile)
#     for row in reader:
#         if len(row) < 2:
#             continue  # 두 개의 열이 없는 경우 건너뜀

#         question_content = row[0].strip() if row[0] else ''
#         answer_content = row[1].strip() if len(row) > 1 else ''

#         # MySQL에 데이터 삽입
#         sql = "INSERT INTO questions05 (question_content, answer_content) VALUES (%s, %s)"
#         cursor.execute(sql, (question_content, answer_content))

# # 변경 사항 저장 및 연결 종료
# conn.commit()
# cursor.close()
# conn.close()

# print("데이터 입력 완료!")



import csv
import pymysql

# MySQL 연결 설정
conn = pymysql.connect(
    host='localhost',
    user='air',
    password='Sapporo2025AirPJT!@',  # 위에서 설정한 비밀번호 입력
    database='AIR',
    charset='utf8mb4'
)

cursor = conn.cursor()

# CSV 파일 읽기 (헤더 없음)
csv_file_path = 'data01.csv'  # CSV 파일 경로 설정
with open(csv_file_path, newline='', encoding='utf-8') as csvfile:
    reader = csv.reader(csvfile)
    for row in reader:
        if len(row) < 4:
            continue  # 최소 4개의 열이 없으면 건너뜀

        question_content = row[0].strip() if row[0] else ''
        answer_content = row[1].strip() if len(row) > 1 else ''
        keyword1 = row[2].strip() if len(row) > 2 else ''
        keyword2 = row[3].strip() if len(row) > 3 else ''

        # MySQL에 데이터 삽입
        sql = """
        INSERT INTO questions01 (question_content, answer_content, keyword1, keyword2)
        VALUES (%s, %s, %s, %s)
        """
        cursor.execute(sql, (question_content, answer_content, keyword1, keyword2))

# 변경 사항 저장 및 연결 종료
conn.commit()
cursor.close()
conn.close()

print("데이터 입력 완료!")
