Rechercher dans le manuel MySQL
28.7.7.21 mysql_fetch_row()
MYSQL_ROW mysql_fetch_row(MYSQL_RES *result)
Description
mysql_fetch_row()
is a
synchronous function. Its asynchronous counterpart is
mysql_fetch_row_nonblocking()
,
for use by applications that require asynchronous
communication with the server. See
Section 28.7.12, “C API Asynchronous Interface”.
mysql_fetch_row()
retrieves
the next row of a result set:
When used after
mysql_store_result()
ormysql_store_result_nonblocking()
,mysql_fetch_row()
returnsNULL
if there are no more rows to retrieve.When used after
mysql_use_result()
,mysql_fetch_row()
returnsNULL
if there are no more rows to retrieve or an error occurred.
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.
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()
:
When used after
mysql_store_result()
ormysql_store_result_nonblocking()
,mysql_fetch_row()
returnsNULL
if there are no more rows to retrieve.When used after
mysql_use_result()
,mysql_fetch_row()
returnsNULL
if there are no more rows to retrieve or an error occurred. To determine whether an error occurred, check whethermysql_error()
returns a nonempty string ormysql_errno()
returns nonzero.
Errors are not reset between calls to
mysql_fetch_row()
The connection to the server was lost during the query.
An unknown error occurred.
MYSQL_ROW 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");
}
printf("\n");
}
Document created the 26/06/2006, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/mysql-rf-mysql-fetch-row.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.