Documentation Home
MySQL 8.0 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 37.4Mb
PDF (A4) - 37.4Mb
PDF (RPM) - 33.8Mb
HTML Download (TGZ) - 8.3Mb
HTML Download (Zip) - 8.4Mb
HTML Download (RPM) - 7.3Mb
Man Pages (TGZ) - 129.8Kb
Man Pages (Zip) - 185.4Kb
Info (Gzip) - 3.3Mb
Info (Zip) - 3.3Mb


MySQL 8.0 Reference Manual  /  ...  /  mysql_fetch_field_direct()

Pre-General Availability Draft: 2018-02-23

28.7.7.18 mysql_fetch_field_direct()

MYSQL_FIELD *mysql_fetch_field_direct(MYSQL_RES *result, unsigned int fieldnr)

Description

Given a field number fieldnr for a column within a result set, returns that column's field definition as a MYSQL_FIELD structure. Use this function to retrieve the definition for an arbitrary column. Specify a value for fieldnr in the range from 0 to mysql_num_fields(result)-1.

For metadata-optional connections, this function returns NULL when the resultset_metadata system variable is set to NONE. To check whether a result set has metadata, use the mysql_result_metadata() function. For details about managing result set metadata transfer, see Section 28.7.23, “C API Optional Result Set Metadata”.

Return Values

The MYSQL_FIELD structure for the specified column. NULL if the result set has no metadata.

Errors

None.

Example
unsigned int num_fields;
unsigned int i;
MYSQL_FIELD *field;

num_fields = mysql_num_fields(result);
for(i = 0; i < num_fields; i++)
{
    field = mysql_fetch_field_direct(result, i);
    printf("Field %u is %s\n", i, field->name);
}

User Comments
  Posted by Rick Pfahl on September 28, 2005
If you are experiencing problems with mysql_fetch_fields(MYSQL_RES*)
(i.e., mysql_fetch_fields is not returning array of MYSQL_FIELD, but rather a pointer the first field) use mysql_fetch_field_direct(MYSQL_RES*, int) instead.
Sign Up Login You must be logged in to post a comment.