mysqli_stmt::fetch

(PHP 5, PHP 7, PHP 8)

mysqli_stmt::fetch -- mysqli_stmt_fetch — 준비된 명령문에서 바인딩된 변수로 결과를 가져옵니다.


설명

객체 지향 스타일

public mysqli_stmt::fetch(): ?bool

절차적 스타일

mysqli_stmt_fetch(mysqli_stmt $statement): ?bool

준비된 명령문에서 결과를 mysqli_stmt_bind_result()에 의해 바인딩된 변수로 가져옵니다.

메모: 모든 열은 mysqli_stmt_fetch()를 호출하기 전에 애플리케이션에 의해 바인딩되어야 합니다.

메모: 데이터는 mysqli_stmt_store_result()를 호출하지 않고 버퍼링되지 않은 상태로 전송되어 성능을 저하시킬 수 있지만 메모리 비용은 줄입니다.


매개변수

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

반환 값

반환 값

Value 설명
true 성공. 데이터를 가져왔습니다
false 오류가 발생했습니다
null 행/데이터가 더 이상 존재하지 않거나 데이터 잘림이 발생했습니다.

Examples

예제 #1 객체 지향 스타일

                  
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$query = "SELECT Name, CountryCode FROM City ORDER by ID DESC LIMIT 150,5";

if ($stmt = $mysqli->prepare($query)) {

    /* execute statement */
    $stmt->execute();

    /* bind result variables */
    $stmt->bind_result($name, $code);

    /* fetch values */
    while ($stmt->fetch()) {
        printf ("%s (%s)\n", $name, $code);
    }

    /* close statement */
    $stmt->close();
}

/* close connection */
$mysqli->close();
?>
                  
                

예제 #2 절차적 스타일

                  
<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "world");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$query = "SELECT Name, CountryCode FROM City ORDER by ID DESC LIMIT 150,5";

if ($stmt = mysqli_prepare($link, $query)) {

    /* execute statement */
    mysqli_stmt_execute($stmt);

    /* bind result variables */
    mysqli_stmt_bind_result($stmt, $name, $code);

    /* fetch values */
    while (mysqli_stmt_fetch($stmt)) {
        printf ("%s (%s)\n", $name, $code);
    }

    /* close statement */
    mysqli_stmt_close($stmt);
}

/* close connection */
mysqli_close($link);
?>
                  
                

위의 예는 다음을 출력합니다.

Rockford (USA)
Tallahassee (USA)
Salinas (USA)
Santa Clarita (USA)
Springfield (USA)
                

기타