The mysqli_field_count() function returns the number of columns for the most recent query.
mysqli_field_count(connection);