728x90
update도 전체적인 구조는 비슷하지만 cursor로 query와 record를 싱행시킨 후 commit을 해주어야 한다.
def put(self, recipe_id) :
data = request.get_json()
try :
connection = get_connection()
query = '''update recipe
set
name = %s,
description = %s,
num_of_servings = %s,
cook_time = %s,
directions = %s
where id = %s;'''
record = (data['name'],data['description'],data['num_of_servings'],data['cook_time'],data['directions'],recipe_id)
cursor = connection.cursor()
cursor.execute(query, record)
connection.commit()
cursor.close()
connection.close()
except Error as e :
print(e)
cursor.close()
connection.close()
return {'result' : 'fail', 'error' : str(e)}, 500
return {'result' : 'success' }, 200
728x90
'API 서버' 카테고리의 다른 글
API 서버 - 1월 4일 학습 정리 (0) | 2023.01.04 |
---|---|
API 서버 - python MySQL Connector를 이용해 delete 하는 방법 (0) | 2023.01.04 |
API 서버 - python MySQL Connector를 이용해 select 하는 방법 (0) | 2023.01.04 |
API 서버 - python MySQL Connector를 이용해 insert 하는 방법 (1) | 2023.01.04 |
API 서버 - mysql과 서버 연동하기(connection) (0) | 2023.01.04 |