mysql_fetch_field



PHP mysql_fetch_field() 函数

定义和用法

mysql_fetch_field() 函数从结果集中取得列信息并作为对象返回。

mysql_fetch_field() 可以用来从查询结果中取得字段的信息。如果没有指定字段偏移量,则提取下一个尚未被 mysql_fetch_field() 取得的字段。

该函数返回一个包含字段信息的对象。

被返回的对象的属性为:

  • name – 列名

  • table – 该列所在的表名

  • max_length – 该列最大长度

  • not_null – 1,如果该列不能为 NULL

  • primary_key – 1,如果该列是 primary key

  • unique_key – 1,如果该列是 unique key

  • multiple_key – 1,如果该列是 non-unique key

  • numeric – 1,如果该列是 numeric

  • blob – 1,如果该列是 BLOB

  • type – 该列的类型

  • unsigned – 1,如果该列是无符号数

  • zerofill – 1,如果该列是 zero-filled

语法

mysql_fetch_field(data,field_offset)

参数 描述
data 必需。要使用的数据指针。该数据指针是从 mysql_query() 返回的结果。
field_offset 必需。规定从哪个字段开始。0 指示第一个字段。如果未设置,则取回下一个字段。

提示和注释

注释:本函数返回的字段名是区分大小写的。

例子

name . "
";   echo "Table name: " . $property->table . "
";   echo "Default value: " . $property->def . "
";   echo "Max length: " . $property->max_length . "
";   echo "Not NULL: " . $property->not_null . "
";    echo "Primary Key: " . $property->primary_key . "
";   echo "Unique Key: " . $property->unique_key . "
";    echo "Mutliple Key: " . $property->multiple_key . "
";   echo "Numeric Field: " . $property->numeric . "
";   echo "BLOB: " . $property->blob . "
";   echo "Field Type: " . $property->type . "
";   echo "Unsigned: " . $property->unsigned . "
";   echo "Zero-filled: " . $property->zerofill . "

";    } mysql_close($con); ?>

输出:

Field name: LastName
Table name: Person
Default value: 
Max length: 8
Not NULL: 0
Primary Key: 0
Unique Key: 0
Mutliple Key: 0
Numeric Field: 0
BLOB: 0
Field Type: string
Unsigned: 0
Zero-filled: 0

Field name: FirstName
Table name: Person
Default value: 
Max length: 7
Not NULL: 0
Primary Key: 0
Unique Key: 0
Mutliple Key: 0
Numeric Field: 0
BLOB: 0
Field Type: string
Unsigned: 0
Zero-filled: 0

Field name: City
Table name: Person
Default value: 
Max length: 9
Not NULL: 0
Primary Key: 0
Unique Key: 0
Mutliple Key: 0
Numeric Field: 0
BLOB: 0
Field Type: string
Unsigned: 0
Zero-filled: 0

Field name: Age
Table name: Person
Default value: 
Max length: 2
Not NULL: 0
Primary Key: 0
Unique Key: 0
Mutliple Key: 0
Numeric Field: 1
BLOB: 0
Field Type: int
Unsigned: 0
Zero-filled: 0

温馨提示: 本文最后更新于2024-12-31 20:06:55,某些文章具有时效性,若有错误或已失效,请在下方 留言或联系 蚂蚁官方
© 版权声明
THE END
喜欢就支持一下吧
点赞6赞赏 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容