PHP 手冊
上一頁 |  | 下一頁

# mysql_list_fields

(PHP 3, PHP 4 , PHP 5)

mysql_list_fields -- List MySQL table fields

## Description

resource mysql_list_fields ( string database_name, string table_name [, resource link_identifier])

> 備注: The function mysql_list_fields() is deprecated. It is preferable to use mysql_query() to issue a SQL SHOW COLUMNS FROM table [LIKE 'name'] Statement instead.

mysql_list_fields() retrieves information about the given table name. Arguments are the database and the table name. A result pointer is returned which can be used with mysql_field_flags(), mysql_field_len(), mysql_field_name(), and mysql_field_type().

示範 1.Alternate to deprecated mysql_list_fields()
`<?php $result = mysql_query("SHOW COLUMNS FROM sometable"); if (!$result) { echo 'Could not run query: ' . mysql_error(); exit; } if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_assoc($result)) { print_r($row); } } ?>`
The above example would produce output similar to:
    Array
    (
        [Field] => id
        [Type] => int(7)
        [Null] =>
        [Key] => PRI
        [Default] =>
        [Extra] => auto_increment
    )
    Array
    (
        [Field] => email
        [Type] => varchar(100)
        [Null] =>
        [Key] =>
        [Default] =>
        [Extra] =>
    )

For downward compatibility mysql_listfields() can also be used. This is deprecated however.

See also mysql_field_flags() and mysql_info().

上一頁 | 最開頭 | 下一頁
mysql_list_dbs | 上一層 | mysql_list_processes