mysqli_result::fetch_field_direct
(PHP 5, PHP 7, PHP 8)
mysqli_result::fetch_field_direct -- mysqli_fetch_field_direct - 단일 필드에 대한 메타 데이터 가져오기
설명
객체 지향 스타일
public mysqli_result::fetch_field_direct(int $index
): object|false
절차적 스타일
mysqli_fetch_field_direct(mysqli_result $result
, int $index
): object|false
지정된 결과 집합의 필드 정의 정보가 포함된 개체를 반환합니다.
매개변수
result
- 절차적 스타일 전용: mysqli_query(), mysqli_store_result(), mysqli_use_result() 또는 mysqli_stmt_get_result()에 의해 반환된 mysqli_result 객체.
index
- 필드 번호입니다. 이 값은
0
에서number of fields - 1
사이여야 합니다.
반환 값
필드 정의 정보가 포함된 개체를 반환하거나 지정된 fieldnr
에 대한 필드 정보를 사용할 수 없는 경우 false
를 반환합니다.
개체 속성
Attribute | 설명 |
---|---|
name | 열의 이름 |
orgname | 별칭이 지정된 경우 원래 열 이름 |
table | 이 필드가 속한 테이블의 이름(계산되지 않은 경우) |
orgtable | 별칭이 지정된 경우 원래 테이블 이름 |
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 Name LIMIT 5";
if ($result = $mysqli->query($query)) {
/* Get field information for column 'SurfaceArea' */
$finfo = $result->fetch_field_direct(1);
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", $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 Name LIMIT 5";
if ($result = mysqli_query($link, $query)) {
/* Get field information for column 'SurfaceArea' */
$finfo = mysqli_fetch_field_direct($result, 1);
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", $finfo->type);
mysqli_free_result($result);
}
/* close connection */
mysqli_close($link);
?>
위의 예는 다음을 출력합니다.
Name: SurfaceArea Table: Country max. Len: 10 Flags: 32769 Type: 4
기타
- mysqli_num_fields() - 결과 집합의 필드 수를 가져옵니다.
- mysqli_fetch_field() - 결과 집합의 다음 필드를 반환합니다.
- mysqli_fetch_fields() - 결과 집합의 필드를 나타내는 개체 배열을 반환합니다.