How to use mysql field name in PHP

In this article I am going to explain about mysql_field_name function in PHP.
  • 1787

PHP mysql_field_name() Function

The PHP mysql_field_name function is used to returns the name of a field in a recordset. It returns field name on success, or false on failure.

Syntax of mysql_field_name function

mysql_field_name(data, fieldOffset)

Parameters in mysql_field_name function

It have two parameter:

Parameter Description
data It specifies which data pointer to use.
fieldOffset It specifies which field to start returning.

Example of mysql_field_name function

<?php

$con=mysql_connect("localhost","gupta","sharad");

if(!$con)

{

die("Could not connect:".mysql_error());

}

mysql_select_db("Mcn_Solution",$con);

$qry=mysql_query("select * from Emp");

$FirstName=mysql_field_name($qry,0);

$LastName=mysql_field_name($qry,1);

$Id=mysql_field_name($qry,2);

echo "Emp table First Column is denoted by:  ".$FirstName;

echo "<br/>";

echo "Emp table Second column is denoted by:  ".$LastName;

echo "<br/>";

echo "Emp table Thrid column is denoted by:  ".$Id;

mysql_close($con);

?>


Output:

mysql-field-name-php.jpg

You may also want to read these related articles :
here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.