mysql_field_name

(PHP 3, PHP 4 )

mysql_field_name --  取得结果中指定字段的字段名

说明

string mysql_field_name ( resource result, int field_index)

mysql_field_name() 返回指定字段索引的字段名。result 必须是一个合法的结果标识符,field_index 是该字段的数字偏移量。

注: field_index 从 0 开始。

例如,第三个字段的索引值其实是 2,第四个字段的索引值是 3,以此类推。

例子 1. mysql_field_name() 例子

/* The users table consists of three fields:
 *   user_id
 *   username
 *   password.
 */
$link = mysql_connect('localhost', "mysql_user", "mysql_password");
mysql_select_db($dbname, $link)
    or die("Could not set $dbname: " . mysql_error());
$res = mysql_query("select * from users", $link);

echo mysql_field_name($res, 0) . "\n";
echo mysql_field_name($res, 2);

以上例子将产生如下输出:
user_id
password

为向下兼容仍然可以使用 mysql_fieldname(),但反对这样做。