Oracle 5.0 Reference Manual page 2189

Table of Contents

Advertisement

Note that you can get the number of columns either from a pointer to a result set or to a
connection handle. You would use the connection handle if
mysql_use_result()
call
mysql_field_count()
a nonempty result. This enables the client program to take proper action without knowing whether the
query was a
done.
See
Section 20.6.13.1, "Why
mysql_query()
Return Values
An unsigned integer representing the number of columns in a result set.
Errors
None.
Example
MYSQL_RES *result;
unsigned int num_fields;
unsigned int num_rows;
if (mysql_query(&mysql,query_string))
{
// error
}
else // query succeeded, process any data returned by it
{
result = mysql_store_result(&mysql);
if (result)
{
num_fields = mysql_num_fields(result);
// retrieve rows, then call mysql_free_result(result)
}
else
// mysql_store_result() returned nothing; should it have?
{
if (mysql_errno(&mysql))
{
fprintf(stderr, "Error: %s\n", mysql_error(&mysql));
}
else if (mysql_field_count(&mysql) == 0)
{
}
}
}
An alternative (if you know that your query should have returned a result set) is to replace the
mysql_errno(&mysql)
happens only if something went wrong.
20.6.6.48.
mysql_num_rows()
my_ulonglong mysql_num_rows(MYSQL_RES *result)
Description
Returns the number of rows in the result set.
The use of
mysql_num_rows()
or
mysql_use_result()
mysql_num_rows()
C API Function Descriptions
returned
NULL
to determine whether
(or SELECT-like) statement. The example shown here illustrates how this may be
SELECT
mysql_store_result()
Returns
Success".
// there are rows
// query does not return data
// (it was not a SELECT)
num_rows = mysql_affected_rows(&mysql);
call with a check whether
depends on whether you use
to return the result set. If you use mysql_store_result(),
may be called immediately. If you use mysql_use_result(),
mysql_store_result()
(and thus you have no result set pointer). In this case, you can
mysql_store_result()
Sometimes Returns
mysql_field_count(&mysql)
2169
should have produced
After
NULL
mysql_store_result()
or
returns 0. This

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents