
mysqli_stmt::fetch 함수를 사용할 때는 prepare() 함수를 사용하여 쿼리를 준비한 후 execute() 함수를 사용하여 쿼리를 실행한 후에 get_result() 함수를 사용하여 결과를 가져와야 합니다.
이러한 오류는 prepare() 함수를 사용하지 않고 execute() 함수를 사용하여 쿼리를 실행한 후 get_result() 함수를 사용하여 결과를 가져왔을 때 발생합니다.
prepare() 함수를 사용하여 쿼리를 준비하고 execute() 함수를 사용하여 쿼리를 실행한 후 get_result() 함수를 사용하여 결과를 가져오는 코드를 다음과 같이 수정할 수 있습니다.
#hostingforum.kr
php
$stmt = $mysqli->prepare("SELECT * FROM users");
$stmt->execute();
$stmt->bind_result($id);
while ($stmt->fetch()) {
echo $id;
}
또는
#hostingforum.kr
php
$stmt = $mysqli->prepare("SELECT * FROM users");
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
echo $row['id'];
}
위의 두 코드 모두 prepare() 함수를 사용하여 쿼리를 준비하고 execute() 함수를 사용하여 쿼리를 실행한 후 get_result() 함수를 사용하여 결과를 가져와서 mysqli_stmt::fetch 함수를 사용하지 않습니다.
2025-03-31 13:16