You can call the mysql_field_count() function to return the number of columns for the most recent query.
Syntax
unsigned int
mysql_field_count(MYSQL *mysql)
Return values
An unsigned integer representing the number of columns in a result set is returned.
Errors
None.
Notes
Generally, this function is used when mysql_store_result() returns NULL. In this case, you can call mysql_field_count() to determine whether mysql_store_result() should have produced a nonempty result. This enables the client program to take proper actions without knowing whether the query was a SELECT (or SELECT-like) statement.