mysql fetch fields_函数mysql_fetch_field的使用详解

[导读]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 指示第一个字段。如果未设置,则取回下一个字段。

提示和注释

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

例子<?php $con = mysql_connect("localhost", "hello", "321");if (!$con)  {  die(could not connect:  . mysql_error());  }$db_selected = mysql_select_db("test_db",$con);$sql = "select * from person";$result = mysql_query($sql,$con);while ($property = mysql_fetch_field($result))  {  echo "field name: " . $property->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: lastnametable name: persondefault value: max length: 8not null: 0primary key: 0unique key: 0mutliple key: 0numeric field: 0blob: 0field type: stringunsigned: 0zero-filled: 0field name: firstnametable name: persondefault value: max length: 7not null: 0primary key: 0unique key: 0mutliple key: 0numeric field: 0blob: 0field type: stringunsigned: 0zero-filled: 0field name: citytable name: persondefault value: max length: 9not null: 0primary key: 0unique key: 0mutliple key: 0numeric field: 0blob: 0field type: stringunsigned: 0zero-filled: 0field name: agetable name: persondefault value: max length: 2not null: 0primary key: 0unique key: 0mutliple key: 0numeric field: 1blob: 0field type: intunsigned: 0zero-filled: 0

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值