Name

mysql_fetch_fields( )

Synopsis

MYSQL_FIELD *mysql_fetch_fields(MYSQL_RES *result)

This returns an array of information about the fields in a results set.

...
mysql_query(mysql, "SELECT * FROM clients");
result = mysql_store_result(mysql);
num_fields = mysql_field_count(mysql);
MYSQL_FIELD *field;
field = mysql_fetch_fields(result);
for(i = 0; i < num_fields; i++)
   { printf("%u. %s \n", i, &field[i].name); }
...

In addition to the .name key to extract the column name, a program can specify .table for the table name and .def for the default value of the column.

Get MySQL in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.