Name

mysql_fetch_field( )

Synopsis

MYSQL_FIELD *mysql_fetch_field(MYSQL_RES *result)

This returns a MYSQL_FIELD structure that provides information on a given field of a results set. If you use it in conjunction with a loop statement, you can extract information on each field.

...
MYSQL_FIELD *field;
...
mysql_query(mysql, "SELECT * FROM clients LIMIT 1");
result = mysql_store_result(mysql);
while((field = mysql_fetch_field(result)) != NULL)
   { printf("%s \n", field->name);  }
...

The wildcard in the SELECT statement selects all columns in the table. The loop therefore lists the name of each column. The other possibilities are field->table for the table name and field->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.