home support FAQ resources services partners contact us contact us
 MySQL Tutorial Previous  Next  
 

Using Result Set Metadata

Result sets contain not only the column values for data rows but also information about the data. This information is called the result set metadata, which includes:

The number of rows and columns in the result set, available by calling mysql_num_rows() and mysql_num_fields().

The length of each column value in the current row, available by calling mysql_fetch_lengths().

Information about each column, such as the column name and type, the maximum width of each column's values, and the table the column comes from. This information is stored in MYSQL_FIELD structures, which typically are obtained by calling mysql_fetch_field(). Appendix F describes the MYSQL_FIELD structure in detail and lists all functions that provide access to column information.

Metadata availability is partially dependent on your result set processing method. As indicated in the previous section, if you want to use the row count or maximum column length values, you must create the result set with mysql_store_result(), not with mysql_use_result().

Result set metadata is helpful for making decisions about how to process result set data:

Column names and widths are useful for producing nicely formatted output that has column titles and that lines up vertically.

You use the column count to determine how many times to iterate through a loop that processes successive column values for data rows.

You can use the row or column counts if you need to allocate data structures that depend on knowing the dimensions of the result set.

You can determine the data type of a column. This allows you to tell whether a column represents a number, whether it contains binary data, and so forth.
Previous  Next  
Link Partners: Asia florist, Flowers to India, Hong kong flowers, Site submit, Cheap web hosting, China florist, Japan florist