当前位置: 首页 > 网络学院 > 服务端脚本教程 > PHP > mysql_fetch_field() 函数

PHP
PHP 介绍
PHP 安装
PHP 语法
PHP 变量
PHP操作符
PHP If...Else
PHP Switch
PHP 数组
PHP 循环
PHP 函数
PHP 表单
PHP $_GET
PHP $_POST
PHP Date
PHP Include
PHP 文件处理
PHP 文件上传
PHP Cookies
PHP Sessions
PHP 发送邮件

PHP 中的 mysql_fetch_field() 函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 650 ::
收藏到网摘: n/a

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
语法

mysql_fetch_field(data,field_offset)

Parameter
参数
Description
描述
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: 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: Address
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

评论 (0) All

登陆 | 还没注册?