Name

mysql_fetch_lengths( )

Synopsis

unsigned long *mysql_fetch_lengths(MYSQL *result)

This returns the length of each column within a particular row of a results set. The values returned can vary for each row fetched, depending on the data contained in the columns.

...
mysql_query(mysql, "SELECT * FROM clients");
result = mysql_store_result(mysql);
row = mysql_fetch_row(result);
unsigned int num_fields = mysql_num_fields(result);
unsigned long *lengths = mysql_fetch_lengths(result);
for(i = 0; i < num_fields; i++)
   {
    field = mysql_fetch_field(result);
    printf("%s %lu \n", field->name, lengths[i]);
   }
...

This example retrieves one row of the results and checks the lengths of the fields in that row. To retrieve each field, the SELECT statement would need to be altered and a while statement would be wrapped around the for statement to loop through each row.

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.