mysqli_stmt::get_result

(PHP 5 >= 5.3.0, PHP 7, PHP 8)

mysqli_stmt::get_result -- mysqli_stmt_get_result — 준비된 명령문에서 결과 집합을 mysqli_result 객체로 가져옵니다.


설명

객체 지향 스타일

public mysqli_stmt::get_result(): mysqli_result|false

절차적 스타일

mysqli_stmt_get_result(mysqli_stmt $statement): mysqli_result|false

준비된 명령문에서 결과 세트를 mysqli_result 객체로 검색합니다. 데이터는 MySQL 서버에서 PHP로 가져옵니다. 이 메서드는 결과 집합을 생성하는 쿼리에 대해서만 호출해야 합니다.

메모: mysqlnd에서만 사용 가능합니다.

메모: 이 함수는 mysqli_stmt_store_result()와 함께 사용할 수 없습니다. 이 두 함수는 모두 MySQL 서버에서 전체 결과 세트를 검색합니다.


매개변수

statement
절차적 스타일 전용: mysqli_stmt_init()에 의해 반환된 mysqli_stmt 객체.

반환 값

실패 시 false를 반환합니다. SELECT, SHOW, DESCRIBE 또는 EXPLAIN과 같은 결과 집합을 생성하는 성공적인 쿼리의 경우 mysqli_stmt_get_result()mysqli_result 객체를 반환합니다. 다른 성공적인 쿼리의 경우 mysqli_stmt_get_result()false를 반환합니다. mysqli_stmt_errno() 함수는 false에 대한 두 가지 이유를 구별하는 데 사용할 수 있습니다. 버그로 인해 PHP 7.4.13 이전에는 mysqli_errno()를 이 용도로 사용해야 했습니다.


Examples

예제 #1 객체 지향 스타일

객체 지향 스타일

                  
<?php

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");

$query = "SELECT Name, Population, Continent FROM Country WHERE Continent=? ORDER BY Name LIMIT 1";

$stmt = $mysqli->prepare($query);
$stmt->bind_param("s", $continent);

$continentList = array('Europe', 'Africa', 'Asia', 'North America');

foreach ($continentList as $continent) {
    $stmt->execute();
    $result = $stmt->get_result();
    while ($row = $result->fetch_array(MYSQLI_NUM)) {
        foreach ($row as $r) {
            print "$r ";
        }
        print "\n";
    }
}
                  
                

예제 #2 절차적 스타일

                  
<?php

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$link = mysqli_connect("localhost", "my_user", "my_password", "world");

$query = "SELECT Name, Population, Continent FROM Country WHERE Continent=? ORDER BY Name LIMIT 1";

$stmt = mysqli_prepare($link, $query);
mysqli_stmt_bind_param($stmt, "s", $continent);

$continentList= array('Europe', 'Africa', 'Asia', 'North America');

foreach ($continentList as $continent) {
    mysqli_stmt_execute($stmt);
    $result = mysqli_stmt_get_result($stmt);
    while ($row = mysqli_fetch_array($result, MYSQLI_NUM)) {
        foreach ($row as $r) {
            print "$r ";
        }
        print "\n";
    }
}
                  
                

위의 예는 다음과 유사한 결과를 출력합니다.

Albania 3401200 Europe
Algeria 31471000 Africa
Afghanistan 22720000 Asia
Anguilla 8000 North America
                

기타