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

mysqli_result::fetch_field

(PHP 5, PHP 7)

mysqli_result :: fetch_field -- mysqli_fetch_field — 返回结果集中的下一个字段

描述

面向对象的风格

代码语言:javascript
复制
object mysqli_result::fetch_field ( void )

程序风格

代码语言:javascript
复制
object mysqli_fetch_field ( mysqli_result $result )

返回结果集中一列的定义作为对象。重复调用此函数以检索有关结果集中所有列的信息。

参数

代码语言:txt
复制
`result`   

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

返回值

返回包含字段定义信息的对象,或者FALSE没有字段信息可用。

属性

描述

name

列的名称

ORGNAME

如果指定了别名,则为原始列名称

该字段所属表的名称(如果未计算)

orgtable

原始表名,如果指定了别名

高清

保留为默认值,目前始终为“”

分贝

数据库(自PHP 5.3.6起)

目录

目录名称始终为“def”(自PHP 5.3.6开始)

最长长度

结果集字段的最大宽度。

长度

字段的宽度,如表定义中所指定。

的charsetnr

字段的字符集编号。

表示字段的位标志的整数。

类型

用于此字段的数据类型

小数点

使用的小数位数(用于整数字段)

例子

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())?{

????????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))?{

????????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
复制
Name:     Name
Table:    Country
max. Len: 11
Flags:    1
Type:     254

Name:     SurfaceArea
Table:    Country
max. Len: 10
Flags:    32769
Type:     4

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com