(PHP 5, PHP 7, PHP 8)
mysqli_result::$current_field -- mysqli_field_tell — 取得結果指標的目前欄位偏移量
result
僅限程序式風格:由 mysqli_query()、mysqli_store_result()、mysqli_use_result() 或 mysqli_stmt_get_result() 傳回的 mysqli_result 物件。
傳回欄位游標的目前偏移量。
範例 #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)) {
/* 取得所有欄位的欄位資訊 */
while ($finfo = $result->fetch_field()) {
/* 取得欄位指標偏移量 */
$currentfield = $result->current_field;
printf("欄位 %d:\n", $currentfield);
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)) {
/* 取得所有欄位的欄位資訊 */
while ($finfo = mysqli_fetch_field($result)) {
/* 取得欄位指標偏移量 */
$currentfield = mysqli_field_tell($result);
printf("欄位 %d:\n", $currentfield);
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);
?>
以上範例將輸出
Column 1: Name: Name Table: Country max. Len: 11 Flags: 1 Type: 254 Column 2: Name: SurfaceArea Table: Country max. Len: 10 Flags: 32769 Type: 4