C API Function Descriptions
2169
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_store_result()
or
mysql_use_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”
.
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) // there are rows
{
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)
{
// query does not return data
// (it was not a SELECT)
num_rows = mysql_affected_rows(&mysql);
}
}
}
An alternative (if you know that your query should have returned a result set) is to replace the
mysql_errno(&mysql)
call with a check whether
mysql_field_count(&mysql)
returns 0. This
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()
depends on whether you use
mysql_store_result()
or
mysql_use_result()
to return the result set. If you use
mysql_store_result()
,
mysql_num_rows()
may be called immediately. If you use
mysql_use_result()
,
Содержание 5.0
Страница 1: ...MySQL 5 0 Reference Manual ...
Страница 18: ...xviii ...
Страница 60: ...40 ...
Страница 396: ...376 ...
Страница 578: ...558 ...
Страница 636: ...616 ...
Страница 844: ...824 ...
Страница 1234: ...1214 ...
Страница 1426: ...MySQL Proxy Scripting 1406 The following diagram shows an overview of the classes exposed by MySQL Proxy ...
Страница 1427: ...MySQL Proxy Scripting 1407 ...
Страница 1734: ...1714 ...
Страница 1752: ...1732 ...
Страница 1783: ...Configuring Connector ODBC 1763 ...
Страница 1793: ...Connector ODBC Examples 1773 ...
Страница 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Страница 1842: ...Connector Net Installation 1822 5 Once the installation has been completed click Finish to exit the installer ...
Страница 1864: ...Connector Net Visual Studio Integration 1844 Figure 20 24 Debug Stepping Figure 20 25 Function Stepping 1 of 2 ...
Страница 2850: ...2830 ...
Страница 2854: ...2834 ...
Страница 2928: ...2908 ...
Страница 3000: ...2980 ...
Страница 3122: ...3102 ...
Страница 3126: ...3106 ...
Страница 3174: ...3154 ...
Страница 3232: ...3212 ...