Forum und email

mysql_field_name

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

mysql_field_name — Get the name of the specified field in a result

說明

string mysql_field_name ( resource $result , int $field_offset )

mysql_field_name() returns the name of the specified field index.

參數

result

回傳類型為 resource 的結果集。該結果集從 mysql_query() 的呼叫中得到。

field_offset

數字形式的欄位偏移量。field_offset 開始於 0。如果 field_offset 不存在,系統會發出 E_WARNING 級別的警告信息。

Return值

The name of the specified field index on success, or FALSE on failure.

範例

Example#1 mysql_field_name() example

<?php
/* The users table consists of three fields:
*   user_id
*   username
*   password.
*/
$link = @mysql_connect('localhost''mysql_user''mysql_password');
if (!
$link) {
    die(
'Could not connect to MySQL server: ' mysql_error());
}
$dbname 'mydb';
$db_selected mysql_select_db($dbname$link);
if (!
$db_selected) {
    die(
"Could not set $dbname: " mysql_error());
}
$res mysql_query('select * from users'$link);

echo 
mysql_field_name($res0) . "\n";
echo 
mysql_field_name($res2);
?>

上例將輸出:

user_id
password

註釋

Note: 本函式回傳的欄位名是區分大小寫的。

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