import pymysql

class db_con:
    host="syye.net"
    user="pythonUser"
    password="Tjekdfl1324%^"
    database="pythonDB"
    char='utf8'

# MySQL 서버 연결 설정
conn = pymysql.connect(
    host="syye.net",
    user="pythonUser",
    password="Tjekdfl1324%^",
    db="pythonDB",
    charset='utf8',
    autocommit=True)

# 커서 생성
curs = conn.cursor(pymysql.cursors.DictCursor)

#조회
sql ="SELECT * FROM books"
curs.execute(sql)
rows = curs.fetchall()
for data in rows:
    title=data['title']
    author = data['author']
    print(title, author)

#입력
# insert_query = "INSERT INTO books (title, author) VALUES (%s, %s)"
# data = ("책임름 111", "저자1")
# curs.execute(insert_query, data)

#수정
# update_query = "UPDATE books set title=%s, author=%s where id=5"
# data = ("책임름 222", "저자2")
# curs.execute(update_query, data)

#삭제
#delete_query = "DELETE FROM books WHERE id=5"
#curs.execute(delete_query)

# 변경사항을 커밋
conn.commit()

# 연결 및 커서 닫기
curs.close()
conn.close()