C API Function Descriptions
2155
mysql_use_result()
,
mysql_fetch_row()
returns
NULL
when there are no more rows to retrieve
or if 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.
Return Values
A
MYSQL_ROW
structure for the next row.
NULL
if there are no more rows to retrieve or if an error
occurred.
Errors
Note that error is not reset between calls to
mysql_fetch_row()
•
CR_SERVER_LOST
[2942]
The connection to the server was lost during the query.
•
CR_UNKNOWN_ERROR
[2941]
An unknown error occurred.
Example
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");
}
20.6.6.22.
mysql_field_count()
unsigned int mysql_field_count(MYSQL *mysql)
Description
Returns the number of columns for the most recent query on the connection.
The normal use of this function is when
mysql_store_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 nonempty result. This enables the client program
to take proper action without knowing whether the query was a
SELECT
(or
SELECT
-like) statement.
The example shown here illustrates how this may be done.
See
Section 20.6.13.1, “Why
mysql_store_result()
Sometimes Returns
NULL
After
mysql_query()
Returns Success”
.
Summary of Contents for 5.0
Page 1: ...MySQL 5 0 Reference Manual ...
Page 18: ...xviii ...
Page 60: ...40 ...
Page 396: ...376 ...
Page 578: ...558 ...
Page 636: ...616 ...
Page 844: ...824 ...
Page 1234: ...1214 ...
Page 1427: ...MySQL Proxy Scripting 1407 ...
Page 1734: ...1714 ...
Page 1752: ...1732 ...
Page 1783: ...Configuring Connector ODBC 1763 ...
Page 1793: ...Connector ODBC Examples 1773 ...
Page 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Page 2850: ...2830 ...
Page 2854: ...2834 ...
Page 2928: ...2908 ...
Page 3000: ...2980 ...
Page 3122: ...3102 ...
Page 3126: ...3106 ...
Page 3174: ...3154 ...
Page 3232: ...3212 ...