PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<mysql_field_lenmysql_field_seek>
Last updated: Mon, 16 Jul 2012

mysql_field_name

(PHP 3, PHP 4, PHP 5)

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() 例子

<?php
/* The users table consists of three fields:
 *  user_id
 *  username
 *  password.
 */
$link = mysql_connect('localhost', "mysql_user", "mysql_password");
$dbname = "mydb";
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(),但反对这样做。




<mysql_field_lenmysql_field_seek>
 Last updated: Mon, 16 Jul 2012
 
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: http://manual.phpv.net/
Last updated: Thu Jul 7 19:13:47 2005 CST