首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

mysqli_result::$current_field

(PHP 5, PHP 7)

mysqli_result :: $ current_field - mysqli_field_tell - 获取结果指针的当前字段偏移量

描述

面向对象的风格

int $mysqli_result->current_field ;

程序风格

代码语言:javascript
复制
int mysqli_field_tell ( mysqli_result $result )

返回用于最后一个mysqli_fetch_field()调用的字段游标的位置。该值可以用作mysqli_field_seek()的参数。

参数

代码语言:txt
复制
`result`   

仅过程风格:由mysqli_query(),mysqli_store_result()或mysqli_use_result()返回的结果集标识符。

返回值

返回字段光标的当前偏移量。

例子

Example#1面向对象的风格

代码语言:javascript
复制
<?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?all?columns?*/
????while?($finfo?=?$result->fetch_field())?{

????????/*?get?fieldpointer?offset?*/
????????$currentfield?=?$result->current_field;

????????printf("Column?%d:\n",?$currentfield);
????????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程序风格

代码语言:javascript
复制
<?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?all?fields?*/
????while?($finfo?=?mysqli_fetch_field($result))?{

????????/*?get?fieldpointer?offset?*/
????????$currentfield?=?mysqli_field_tell($result);

????????printf("Column?%d:\n",?$currentfield);
????????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);
?>

上面的例子会输出:

代码语言:javascript
复制
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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com