mysqli_result::field_seek
mysqli_result::field_seek
mysqli_field_seek
(PHP 5, PHP 7)
mysqli_result :: field_seek -- mysqli_field_seek — 将结果指针设置为指定的字段偏移量
描述
面向对象的风格
bool mysqli_result::field_seek ( int $fieldnr )
程序风格
bool mysqli_field_seek ( mysqli_result $result , int $fieldnr )
将字段光标设置为给定的偏移量。下一次调用mysqli_fetch_field()将检索与该偏移量关联的列的字段定义。
注意
:为了寻找一行的开始,传递零的偏移值。
参数
`result`
仅过程风格:由mysqli_query(),mysqli_store_result()或mysqli_use_result()返回的结果集标识符。
fieldnr
字段号。该值必须在0
到字段数-1
的范围内。
返回值
成功返回TRUE
或失败时返回FALSE
。
例子
Example#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 Name, SurfaceArea from Country ORDER BY Code LIMIT 5";
if ($result = $mysqli->query($query)) {
/* Get field information for 2nd column */
$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(
}
/* 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 Name, SurfaceArea from Country ORDER BY Code LIMIT 5";
if ($result = mysqli_query($link, $query)) {
/* Get field information for 2nd column */
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
}
/* close connection */
mysqli_close($link
?>
上面的例子会输出:
Name: SurfaceArea
Table: Country
max. Len: 10
Flags: 32769
Type: 4