php mysql_fetch_field() 函数使用方法详解_MySQL, Oracle及数据库讨论区_Weblogic技术|Tuxedo技术|中间件技术|Oracle论坛|JAVA论坛|Linux/Unix技术|hadoop论坛_联动北方技术论坛  
网站首页 | 关于我们 | 服务中心 | 经验交流 | 公司荣誉 | 成功案例 | 合作伙伴 | 联系我们 |
联动北方-国内领先的云技术服务提供商
»  游客             当前位置:  论坛首页 »  自由讨论区 »  MySQL, Oracle及数据库讨论区 »
总帖数
1
每页帖数
101/1页1
返回列表
0
发起投票  发起投票 发新帖子
查看: 2404 | 回复: 0   主题: php mysql_fetch_field() 函数使用方法详解        下一篇 
无止境
注册用户
等级:新兵
经验:64
发帖:74
精华:0
注册:2011-11-14
状态:离线
发送短消息息给无止境 加好友    发送短消息息给无止境 发消息
发表于: IP:您无权察看 2014-11-6 16:19:47 | [全部帖] [楼主帖] 楼主

Definition and Usage

定义和用法

The mysql_fetch_field() function returns an object containing information of a field from a recordset.

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

This function gets field data from the mysql_query() function and returns an object on success, or FALSE on failure or when there are no more rows.

如果函数成功执行,它将获取一行信息(该行是通过执行mysql_query()函数取得的)并返回该行信息;如果失败,将不返回任何一行。

Possible return values:

返回的可能值:

name - Field name

name –字段名

table - The table the field belongs to

table –字段所属的表格

def - Default value for the field

def –字段的默认值

max_length - Maximum field length

max_length –最长字段名

not_null - 1 if the field cannot be NULL

not_null –如果字段不能为空值,那么其值为1

primary_key - 1 if the field is a primary key

primary_key –如果该字段是一个私钥[primary key],那么其值为1

unique_key - 1 if the field is a unique key

unique_key –如果字段是一个独立的键,那么其值为1

multiple_key - 1 if the field is a non-unique key

multiple_key –如果字段是一个非独立键,那么其值为1

numeric - 1 if the field is numeric

numeric –如果字段是数值,那么其值为1

blob - 1 if the field is a BLOB

blob –如果字段是一个点[blob],那么其值为1

type - Field type

type –字段类型

unsigned - 1 if the field is unsigned

unsigned –如果字段是不区分正负号的,那么其值为1

zerofill - 1 if the field is zero-filled

zerofill –如果字段包含0,那么其值为1

Syntax

语法

data

Required. Specifies which data pointer to use. The data pointer is the result from the mysql_query() function

必要参数。指定需要使用的数据指针[data pointer]。该数据指针是通过请求mysql_query()函数返回的。

field_offset

Optional. Specifies which field to start returning. 0 indicates the first field. If this parameter is not set, it will retrieve the next field

可选参数。指定字段的起始位置。0表示第一个字段。如果不指定这个参数,那么它将获取下一个字段

Tips and Notes

注意点

Note: Each subsequent call to mysql_fetch_field() returns the next field in the recordset.

注意:如果接下来继续请求mysql_fetch_array()函数,那么将返回下一条记录。

Example

案例

<?php

$con = mysql_connect("localhost", "peter", "abc123");

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 . "<br />";

    echo "Table name: " . $property->table . "<br />";

    echo "Default value: " . $property->def . "<br />";

    echo "Max length: " . $property->max_length . "<br />";

    echo "Not NULL: " . $property->not_null . "<br />";

    echo "Primary Key: " . $property->primary_key . "<br />";

    echo "Unique Key: " . $property->unique_key . "<br />";

    echo "Mutliple Key: " . $property->multiple_key . "<br />";

    echo "Numeric Field: " . $property->numeric . "<br />";

    echo "BLOB: " . $property->blob . "<br />";

    echo "Field Type: " . $property->type . "<br />";

    echo "Unsigned: " . $property->unsigned . "<br />";

echo "Zero-filled: " . $property->zerofill . "<br /><br />"; }

mysql_close($con);?>

The output of the code above could be:

上述代码将输出下面的结果:

Field name: LastNameTable name: PersonDefault value: Max length: 8Not NULL: 0Primary Key:

0Unique Key: 0Mutliple Key: 0Numeric Field: 0BLOB: 0Field Type: stringUnsigned: 0Zero-filled: 0

Field name: FirstNameTable name: PersonDefault value: Max length: 7Not NULL:

0Primary Key: 0Unique Key: 0Mutliple Key: 0Numeric Field: 0BLOB: 0Field Type:

stringUnsigned: 0Zero-filled: 0

Field name: AddressTable name: PersonDefault value: Max length: 9Not NULL: 0Primary Key:

0Unique Key: 0Mutliple Key: 0Numeric Field: 0BLOB: 0Field Type: stringUnsigned: 0Zero-filled: 0

Field name: AgeTable name: PersonDefault value: Max length: 2Not NULL: 0Primary Key:

0Unique Key: 0Mutliple Key: 0Numeric Field: 1BLOB: 0Field Type: intUnsigned: 0Zero-filled: 0




赞(0)    操作        顶端 
总帖数
1
每页帖数
101/1页1
返回列表
发新帖子
请输入验证码: 点击刷新验证码
您需要登录后才可以回帖 登录 | 注册
技术讨论