Insert
import pymysql
con = pymysql.connect(host='localhost', user='root', port=3305
,password='python', db='python', charset='utf8')
cur = con.cursor()
e_id="3"
e_name="3"
gen="3"
addr="3"
query = f'''
Insert into emp(e_id,e_name,gen,addr)
values('{e_id}','{e_name}','{gen}','{addr}')
'''
cnt = cur.execute(query)
# print("cnt",cur.rowcount) # 성공시 1
print("cnt",cnt) # 성공시 1
con.commit()
cur.close()
con.close()
Update
import pymysql
con = pymysql.connect(host='localhost', user='root', port=3305
,password='python', db='python', charset='utf8')
# cur = conn.cursor(pymysql.cursors.DictCursor)
cur = con.cursor()
e_id="3"
e_name="6"
gen="6"
addr="6"
query = f'''
update emp
set
e_name='{e_name}',
gen='{gen}',
addr='{addr}'
where
e_id='{e_id}'
'''
cnt = cur.execute(query)
# print("cnt",cur.rowcount) # 성공시 1
print("cnt",cnt) # 성공시 1
con.commit()
cur.close()
con.close()
delete
import pymysql
con = pymysql.connect(host='localhost', user='root', port=3305
,password='python', db='python', charset='utf8')
# cur = conn.cursor(pymysql.cursors.DictCursor)
cur = con.cursor()
e_id="3"
query = f'''
delete from emp
where
e_id='{e_id}'
'''
cnt = cur.execute(query)
# print("cnt",cur.rowcount) # 성공시 1
print("cnt",cnt) # 성공시 1
con.commit()
cur.close()
con.close()
'Python > flask' 카테고리의 다른 글
axios (0) | 2024.04.10 |
---|---|
dao 이용한 select,insert,update,delete문 (0) | 2024.04.09 |
render_template (0) | 2024.04.03 |
flask get방식, post 방식 파라미터 넣기 (0) | 2024.04.03 |
flask 서버 실행 (0) | 2024.04.03 |