mysqli_field_seek
result->field_seek()
(No version information available, might be only in CVS)
result->field_seek() — 結果ポインタを、指定したフィールドオフセットに設定する
説明
手続き型:
bool mysqli_field_seek
( mysqli_result $result
, int $fieldnr
)
オブジェクト指向型(メソッド):
mysqli_result
bool field_seek
( int $fieldnr
)
フィールドカーソルを指定したオフセットに設定します。 mysqli_fetch_field() を次にコールした際に、 設定したオフセットに関連するカラムのフィールド定義を取得します。
注意: 行のはじめに移動するには、オフセットとしてゼロを指定します。
パラメータ
- result
-
手続き型のみ: mysqli_query()、mysqli_store_result() あるいは mysqli_use_result() が返す結果セット ID。
- fieldnr
-
フィールド番号。これは 0 から フィールド数 - 1 までの範囲でなければなりません。
返り値
コール前のフィールドカーソルの値を返します。
例
Example#1 オブジェクト指向型
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* 接続状況をチェックします */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query = "SELECT Name, SurfaceArea from Country ORDER BY Code LIMIT 5";
if ($result = $mysqli->query($query)) {
/* 2 番目のカラムのフィールド情報を取得します */
$result->field_seek(1);
$finfo = $result->fetch_field();
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\n", $finfo->type);
$result->close();
}
/* 接続を閉じます */
$mysqli->close();
?>
Example#2 手続き型
<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
/* 接続状況をチェックします */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query = "SELECT Name, SurfaceArea from Country ORDER BY Code LIMIT 5";
if ($result = mysqli_query($link, $query)) {
/* 2 番目のカラムのフィールド情報を取得します */
mysqli_field_seek($result, 1);
$finfo = mysqli_fetch_field($result);
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\n", $finfo->type);
mysqli_free_result($result);
}
/* 接続を閉じます */
mysqli_close($link);
?>
上の例の出力は以下となります。
Name: SurfaceArea Table: Country max. Len: 10 Flags: 32769 Type: 4