How can one extract a field name from a record set in PHP after executing a successful SQL query?

When executing a successful SQL query in PHP and fetching the results as a record set, you can extract a field name by using the `mysqli_fetch_field_direct` function. This function allows you to retrieve information about a field in a result set. By passing the field index as a parameter, you can obtain the name of the field.

// Assuming $result is the variable holding the record set from the SQL query

$fieldIndex = 0; // Index of the field you want to extract the name from
$fieldInfo = mysqli_fetch_field_direct($result, $fieldIndex);
$fieldname = $fieldInfo->name;

echo "Field Name: " . $fieldname;