How to get field name of table using object in php without running a separate query to get column names?

91 Views Asked by At

Hi I am exporting data in excel format and for that I need to first get the field(column) names of table. For that I am using object to do this but I don't know the function name or property to get the field name. Below is a small section of the code I am using to do so it only gets the field names.

$SQL = "SELECT  * from assignments";
$header = '';
$result ='';
$exportData = $conn->query ($SQL ) or die ( "Sql error : " .     $conn->error( ) );

$fields = $exportData->field_count;

for ( $i = 0; $i < $fields; $i++ )
{
    //Get field name using object instead of using mysql_field_name($exportData,$i) because exportData is an object and it wont work.
} 

Edit:I don't want to run separate query to get column names because I am already getting records from that table so I would prefer to use a function or property to get its field names.

0

There are 0 best solutions below