#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pymysql
import sys

# UTF-8 출력 설정
if sys.platform == 'win32':
    import io
    sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')

# 데이터베이스 연결
conn = pymysql.connect(
    host='officialsite.kr',
    user='admin',
    password='dlgks~123',
    database='app_master',
    port=23306,
    charset='utf8mb4'
)

try:
    cursor = conn.cursor()

    # 테이블 구조 확인
    print('===== babynote_news_gallery 테이블 구조 =====')
    cursor.execute('DESCRIBE babynote_news_gallery')

    columns = cursor.fetchall()
    for col in columns:
        print(f'{col[0]:<20} {col[1]:<20} {col[2]:<10} {col[3]:<10}')

    print()
    print('===== 데이터 샘플 =====')
    cursor.execute('SELECT * FROM babynote_news_gallery LIMIT 3')
    rows = cursor.fetchall()

    if rows:
        for row in rows:
            print(row)
    else:
        print('데이터가 없습니다.')

finally:
    cursor.close()
    conn.close()
