
mysqli_stmt::next_result() 함수는 이전 쿼리의 결과를 무시하고 다음 쿼리의 결과를 반환합니다. 이 함수를 호출한 후 stmt->fetch()를 사용하면 오류가 발생합니다. 이는 mysqli_stmt::next_result() 함수가 stmt->fetch() 함수와 동시에 사용할 수 없기 때문입니다.
mysqli_stmt::next_result() 함수의 동작 원리는 다음과 같습니다.
1. 이전 쿼리의 결과를 무시합니다.
2. 다음 쿼리의 결과를 반환합니다.
3. stmt->fetch() 함수를 사용할 수 없습니다.
이를 해결하기 위한 방법은 다음과 같습니다.
1. stmt->next_result() 함수를 호출한 후 stmt->free_result() 함수를 호출하여 이전 쿼리의 결과를 삭제합니다.
2. stmt->next_result() 함수를 호출한 후 stmt->store_result() 함수를 호출하여 다음 쿼리의 결과를 저장합니다.
3. stmt->next_result() 함수를 호출한 후 stmt->fetch_all() 함수를 호출하여 다음 쿼리의 결과를 모두 가져옵니다.
예를 들어, 다음과 같이 쿼리를 실행하고 결과를 가져올 수 있습니다.
#hostingforum.kr
php
$stmt = $mysqli->prepare("SELECT * FROM table1");
$stmt->execute();
$stmt->store_result();
$stmt = $mysqli->prepare("SELECT * FROM table2");
$stmt->execute();
$stmt->store_result();
$result = $stmt->fetch_all(MYSQLI_ASSOC);
또는
#hostingforum.kr
php
$stmt = $mysqli->prepare("SELECT * FROM table1");
$stmt->execute();
$stmt->free_result();
$stmt = $mysqli->prepare("SELECT * FROM table2");
$stmt->execute();
$stmt->store_result();
$result = $stmt->fetch_all(MYSQLI_ASSOC);
이러한 방법으로 stmt->next_result() 함수와 stmt->fetch() 함수를 동시에 사용할 수 있습니다.
2025-08-15 07:05