DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH
 

(mysql.info.gz) mysql_num_fields

Info Catalog (mysql.info.gz) mysql_list_tables (mysql.info.gz) C API functions (mysql.info.gz) mysql_num_rows
 
 22.2.3.41 `mysql_num_fields()'
 ..............................
 
 `unsigned int mysql_num_fields(MYSQL_RES *result)'
 
 Or:
 
 `unsigned int mysql_num_fields(MYSQL *mysql)'
 
 The second form doesn't work on MySQL 3.22.24 or newer.  To pass a
 `MYSQL*' argument, you must use `unsigned int mysql_field_count(MYSQL
 *mysql)' instead.
 
 Description
 ...........
 
 Returns the number of columns in a result set.
 
 Note that you can get the number of columns either from a pointer to a
 result set or to a connection handle.  You would use the connection
 handle if `mysql_store_result()' or `mysql_use_result()' returned
 `NULL' (and thus you have no result set pointer).  In this case, you can
 call `mysql_field_count()' to determine whether `mysql_store_result()'
 should have produced a non-empty result.  This allows the client
 program to take proper action without knowing whether or not the query
 was a `SELECT' (or `SELECT'-like) statement.  The example shown here
 illustrates how this may be done.
 
  `NULL mysql_store_result()' NULL mysql_store_result.
 
 Return Values
 .............
 
 An unsigned integer representing the number of columns in a result set.
 
 Errors
 ......
 
 None.
 
 Example
 .......
 
      MYSQL_RES *result;
      unsigned int num_fields;
      unsigned int num_rows;
 
      if (mysql_query(&mysql,query_string))
      {
          // error
      }
      else // query succeeded, process any data returned by it
      {
          result = mysql_store_result(&mysql);
          if (result)  // there are rows
          {
              num_fields = mysql_num_fields(result);
              // retrieve rows, then call mysql_free_result(result)
          }
          else  // mysql_store_result() returned nothing; should it have?
          {
              if (mysql_errno(&mysql))
              {
                 fprintf(stderr, "Error: %s\n", mysql_error(&mysql));
              }
              else if (mysql_field_count(&mysql) == 0)
              {
                  // query does not return data
                  // (it was not a SELECT)
                  num_rows = mysql_affected_rows(&mysql);
              }
          }
      }
 
 An alternative (if you know that your query should have returned a
 result set) is to replace the `mysql_errno(&mysql)' call with a check
 whether `mysql_field_count(&mysql)' is = 0.  This will happen only if
 something went wrong.
 
Info Catalog (mysql.info.gz) mysql_list_tables (mysql.info.gz) C API functions (mysql.info.gz) mysql_num_rows
automatically generated byinfo2html