PHP Conference Japan 2024

mysqli_result::field_seek

mysqli_field_seek

(PHP 5, PHP 7, PHP 8)

mysqli_result::field_seek -- mysqli_field_seek設定結果指標到指定的欄位偏移量

說明

物件導向風格

public mysqli_result::field_seek(int $index): true

程序式風格

mysqli_field_seek(mysqli_result $result, int $index): true

設定欄位游標到指定的偏移量。下次呼叫 mysqli_fetch_field() 將會擷取與該偏移量關聯的欄位定義。

注意:

要指向列的開頭,請傳遞偏移值零。

參數

result

僅限程序式風格:由 mysqli_query()mysqli_store_result()mysqli_use_result()mysqli_stmt_get_result() 返回的 mysqli_result 物件。

index

欄位編號。此值必須介於 0欄位數 - 1 之間。

返回值

永遠返回 true

更新日誌

版本 說明
8.0.0 此函數現在永遠返回 true。先前它在失敗時返回 false

範例

範例 #1 物件導向風格

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

/* 檢查連線 */
if (mysqli_connect_errno()) {
printf("連線失敗: %s\n", mysqli_connect_error());
exit();
}

$query = "SELECT Name, SurfaceArea from Country ORDER BY Code LIMIT 5";

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

/* 取得第二個欄位的資訊 */
$result->field_seek(1);
$finfo = $result->fetch_field();

printf("名稱: %s\n", $finfo->name);
printf("表格: %s\n", $finfo->table);
printf("最大長度: %d\n", $finfo->max_length);
printf("旗標: %d\n", $finfo->flags);
printf("類型: %d\n\n", $finfo->type);

$result->close();
}

/* 關閉連線 */
$mysqli->close();
?>

範例 #2 程序式風格

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

/* 檢查連線 */
if (mysqli_connect_errno()) {
printf("連線失敗: %s\n", mysqli_connect_error());
exit();
}

$query = "SELECT Name, SurfaceArea from Country ORDER BY Code LIMIT 5";

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

/* 取得第二個欄位的資訊 */
mysqli_field_seek($result, 1);
$finfo = mysqli_fetch_field($result);

printf("名稱: %s\n", $finfo->name);
printf("表格: %s\n", $finfo->table);
printf("最大長度: %d\n", $finfo->max_length);
printf("旗標: %d\n", $finfo->flags);
printf("類型: %d\n\n", $finfo->type);

mysqli_free_result($result);
}

/* 關閉連線 */
mysqli_close($link);
?>

以上範例會輸出

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

另請參閱

新增註釋

使用者貢獻的註釋

此頁面沒有使用者貢獻的註釋。
To Top