PHP mysql_field_name() Function

Definition and Usage

The mysql_field_name() function retrieves the field name of the specified field in the result.

If successful, it returns the field name, if failed, it returns false.

Syntax

mysql_field_name(data,field_offset)
Parameter Description
data Required. The data pointer to be used. The data pointer is from mysql_query() The returned result.
field_offset Required. Indicates which field to start returning from. 0 indicates the first field.

Tips and Comments

Note:The field name returned by this function is case-sensitive.

Example

<?php
$con = mysql_connect("localhost", "hello", "321");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
$db_selected = mysql_select_db("test_db",$con);
$sql = "SELECT * from Person";
$result = mysql_query($sql,$con);
$name = mysql_field_name($result, 0);
echo $name;
mysql_close($con);
?>

Output:

LastName