Documentation Home
MySQL 5.6 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 31.3Mb
PDF (A4) - 31.4Mb
PDF (RPM) - 29.6Mb
HTML Download (TGZ) - 7.3Mb
HTML Download (Zip) - 7.4Mb
HTML Download (RPM) - 6.3Mb
Man Pages (TGZ) - 177.3Kb
Man Pages (Zip) - 287.7Kb
Info (Gzip) - 3.0Mb
Info (Zip) - 3.0Mb
Excerpts from this Manual mysql_fetch_row()

MYSQL_ROW mysql_fetch_row(MYSQL_RES *result)


mysql_fetch_row() retrieves the next row of a result set:

The number of values in the row is given by mysql_num_fields(result). If row holds the return value from a call to mysql_fetch_row(), pointers to the values are accessed as row[0] to row[mysql_num_fields(result)-1]. NULL values in the row are indicated by NULL pointers.

The lengths of the field values in the row may be obtained by calling mysql_fetch_lengths(). Empty fields and fields containing NULL both have length 0; you can distinguish these by checking the pointer for the field value. If the pointer is NULL, the field is NULL; otherwise, the field is empty.

Return Values

A MYSQL_ROW structure for the next row, or NULL. The meaning of a NULL return depends on which function was called preceding mysql_fetch_row():


Errors are not reset between calls to mysql_fetch_row()

unsigned int num_fields;
unsigned int i;

num_fields = mysql_num_fields(result);
while ((row = mysql_fetch_row(result)))
   unsigned long *lengths;
   lengths = mysql_fetch_lengths(result);
   for(i = 0; i < num_fields; i++)
       printf("[%.*s] ", (int) lengths[i],
              row[i] ? row[i] : "NULL");

User Comments
User comments in this section are, as the name implies, provided by MySQL users. The MySQL documentation team is not responsible for, nor do they endorse, any of the information provided here.
  Posted by Vyacheslav Brover on March 29, 2011
Detecting timeout error for non-prepared "select for update" statement:

/* lock table LOG */
MYSQL mysql;
/* initialize mysql */
int status = mysql_query (& mysql, "select Id from LOG for update"); /* Waits for ~1 min., but status == 0 */
unsigned int err = mysql_errno (& mysql); /* err == 0 */
MYSQL_RES* res = mysql_use_result (& mysql);
err = mysql_errno (& mysql); /* err == 0 */
MYSQL_ROW row = mysql_fetch_row (mres);
err = mysql_errno (& mysql); /* err == 1205 (ER_LOCK_WAIT_TIMEOUT) */

For non-prepared DML statements error 1205 is detected by mysql_query().
For prepared statements error 1205 is detected by mysql_stmt_execute().