mysqli_result::fetch_field

(PHP 5, PHP 7, PHP 8)

mysqli_result::fetch_field -- mysqli_fetch_field — 결과 집합에서 다음 필드를 반환합니다.


설명

객체 지향 스타일

public mysqli_result::fetch_field(): object|false

절차적 스타일

mysqli_fetch_field(mysqli_result $result): object|false

결과 집합의 한 열에 대한 정의를 개체로 반환합니다. 이 함수를 반복적으로 호출하여 결과 집합의 모든 열에 대한 정보를 검색합니다.


매개변수

result
절차적 스타일 전용: mysqli_query(), mysqli_store_result(), mysqli_use_result() 또는 mysqli_stmt_get_result()에 의해 반환된 mysqli_result 객체.

반환 값

필드 정의 정보가 포함된 개체를 반환하거나 사용 가능한 필드 정보가 없으면 false를 반환합니다.

개체 속성

Attribute 설명
name 열의 이름
orgname 별칭이 지정된 경우 원래 열 이름
table 이 필드가 속한 테이블의 이름(계산되지 않은 경우)
orgtable 별칭이 지정된 경우 원래 테이블 이름
def 기본값으로 예약되어 있으며 현재 항상 ""
db 데이터베이스의 이름
catalog 카탈로그 이름, 항상 "def"
max_length 결과 집합에 대한 필드의 최대 너비입니다.
length 테이블 정의에 지정된 필드의 너비입니다.
charsetnr 필드의 문자 집합 번호입니다.
flags 필드의 비트 플래그를 나타내는 정수입니다.
type 이 필드에 사용된 데이터 유형
decimals 사용된 소수 자릿수(정수 필드의 경우)

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, SurfaceArea from Country ORDER BY Code LIMIT 5";

if ($result = $mysqli->query($query)) {

    /* Get field information for all columns */
    while ($finfo = $result->fetch_field()) {

        printf("Name:     %s\n", $finfo->name);
        printf("Table:    %s\n", $finfo->table);
        printf("max. Len: %d\n", $finfo->max_length);
        printf("Flags:    %d\n", $finfo->flags);
        printf("Type:     %d\n\n", $finfo->type);
    }
    $result->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, SurfaceArea from Country ORDER BY Code LIMIT 5";

if ($result = mysqli_query($link, $query)) {

    /* Get field information for all fields */
    while ($finfo = mysqli_fetch_field($result)) {

        printf("Name:     %s\n", $finfo->name);
        printf("Table:    %s\n", $finfo->table);
        printf("max. Len: %d\n", $finfo->max_length);
        printf("Flags:    %d\n", $finfo->flags);
        printf("Type:     %d\n\n", $finfo->type);
    }
    mysqli_free_result($result);
}

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

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

Name:     Name
Table:    Country
max. Len: 11
Flags:    1
Type:     254

Name:     SurfaceArea
Table:    Country
max. Len: 10
Flags:    32769
Type:     4
                

기타