mysqli_result::$lengths
(PHP 5, PHP 7, PHP 8)
mysqli_result::$lengths -- mysqli_fetch_lengths — 결과 집합에서 현재 행의 열 길이를 반환합니다.
설명
객체 지향 스타일
?array $mysqli_result->lengths;
절차적 스타일
mysqli_fetch_lengths(mysqli_result $result
): array|false
mysqli_fetch_lengths() 함수는 결과 집합 내 현재 행의 모든 열 길이를 포함하는 배열을 반환합니다.
매개변수
result
- 절차적 스타일 전용: mysqli_query(), mysqli_store_result(), mysqli_use_result() 또는 mysqli_stmt_get_result()에 의해 반환된 mysqli_result 객체.
반환 값
각 열의 크기를 나타내는 정수 배열입니다(종료 null 문자는 포함하지 않음). 오류가 발생하면 false
입니다.
mysqli_fetch_lengths()는 결과 세트의 현재 행에만 유효합니다. mysqli_fetch_row/array/object를 호출하기 전이나 결과의 모든 행을 검색한 후에 호출하면 false
를 반환합니다.
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 * from Country ORDER BY Code LIMIT 1";
if ($result = $mysqli->query($query)) {
$row = $result->fetch_row();
/* display column lengths */
foreach ($result->lengths as $i => $val) {
printf("Field %2d has Length %2d\n", $i+1, $val);
}
$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 * from Country ORDER BY Code LIMIT 1";
if ($result = mysqli_query($link, $query)) {
$row = mysqli_fetch_row($result);
/* display column lengths */
foreach (mysqli_fetch_lengths($result) as $i => $val) {
printf("Field %2d has Length %2d\n", $i+1, $val);
}
mysqli_free_result($result);
}
/* close connection */
mysqli_close($link);
?>
위의 예는 다음을 출력합니다.
Field 1 has Length 3 Field 2 has Length 5 Field 3 has Length 13 Field 4 has Length 9 Field 5 has Length 6 Field 6 has Length 1 Field 7 has Length 6 Field 8 has Length 4 Field 9 has Length 6 Field 10 has Length 6 Field 11 has Length 5 Field 12 has Length 44 Field 13 has Length 7 Field 14 has Length 3 Field 15 has Length 2