Forum und email

mysql_list_fields

(PHP 4, PHP 5, PECL mysql:1.0)

mysql_list_fields — List MySQL table fields

說明

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

Retrieves information about the given table name.

This function is deprecated. It is preferable to use mysql_query() to issue a SQL SHOW COLUMNS FROM table [LIKE 'name'] statement instead.

參數

database_name

The name of the database that's being queried.

table_name

The name of the table that's being queried.

link_identifier

MySQL 的連接識別符。如果沒有指定,預設使用最後被 mysql_connect() 打開的連接。如果沒有找到該連接,函式會嘗試呼叫 mysql_connect() 建立連接並使用它。如果發生意外,沒有找到連接或無法建立連接,系統發出 E_WARNING 級別的警告信息。

Return值

A result pointer resource on success, or FALSE on failure.

The returned result can be used with mysql_field_flags(), mysql_field_len(), mysql_field_name()mysql_field_type().

範例

Example#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);
    }
}
?>

上例的輸出類似於:

Array
(
    [Field] => id
    [Type] => int(7)
    [Null] =>  
    [Key] => PRI
    [Default] =>
    [Extra] => auto_increment
)
Array
(
    [Field] => email
    [Type] => varchar(100)
    [Null] =>
    [Key] =>
    [Default] =>
    [Extra] =>
)

註釋

Note: 為了保證向下相容性,可以使用下面的別名,但不贊成使用它: mysql_listfields()