(PHP 5, PHP 7, PHP 8)
mysqli_result::field_seek -- mysqli_field_seek — 設定結果指標到指定的欄位偏移量
result
僅限程序式風格:由 mysqli_query()、mysqli_store_result()、mysqli_use_result() 或 mysqli_stmt_get_result() 返回的 mysqli_result 物件。
index
欄位編號。此值必須介於 0
到 欄位數 - 1
之間。
永遠返回 true
。
範例 #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