
mysqli_stmt::bind_result와 fetch_result의 차이점은 다음과 같습니다.
- mysqli_stmt::bind_result는 결과를 받을 변수를 선언하여 bind_result 메소드에 전달해야 합니다. 이 변수는 bind_result 메소드의 인자로 전달되어 결과를 받을 변수의 위치를 지정합니다.
- fetch_result는 결과를 받을 변수를 선언하지 않아도 됩니다. 대신, fetch_result 메소드는 결과를 받을 변수의 위치를 자동으로 지정합니다.
- mysqli_stmt::bind_result는 결과를 받을 변수의 타입을 지정해야 합니다. 예를 들어, int, float, string 등이 있습니다. fetch_result도 결과를 받을 변수의 타입을 지정해야 합니다.
- mysqli_stmt::bind_result는 결과를 받을 변수의 개수를 지정해야 합니다. fetch_result도 결과를 받을 변수의 개수를 지정해야 합니다.
- mysqli_stmt::bind_result는 결과를 받을 변수의 순서를 지정해야 합니다. fetch_result도 결과를 받을 변수의 순서를 지정해야 합니다.
예를 들어, 다음과 같이 mysqli_stmt::bind_result를 사용할 수 있습니다.
#hostingforum.kr
php
$stmt = $mysqli->prepare("SELECT * FROM users");
$stmt->execute();
$stmt->bind_result($id, $name, $email);
while ($stmt->fetch()) {
echo "ID: $id, Name: $name, Email: $emailn";
}
fetch_result를 사용할 때는 다음과 같이 사용할 수 있습니다.
#hostingforum.kr
php
$stmt = $mysqli->prepare("SELECT * FROM users");
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
echo "ID: " . $row['id'] . ", Name: " . $row['name'] . ", Email: " . $row['email'] . "n";
}
mysqli_stmt::bind_result는 결과를 받을 변수의 타입을 지정해야 하므로, 결과를 받을 변수의 타입이 맞지 않으면 에러가 발생할 수 있습니다. fetch_result는 결과를 받을 변수의 타입을 지정하지 않아도 되므로, 결과를 받을 변수의 타입이 맞지 않더라도 에러가 발생하지 않습니다.
2025-05-28 14:13