Oracle 5.0 Reference Manual page 2163

Table of Contents

Advertisement

For each
non-SELECT
rows were changed (affected) by calling mysql_affected_rows().
For
queries, you retrieve the selected rows as a result set. (Note that some statements are
SELECT
SELECT-like in that they return rows. These include SHOW, DESCRIBE, and EXPLAIN. Treat these
statements the same way as
There are two ways for a client to process result sets. One way is to retrieve the entire result set all at
once by calling mysql_store_result(). This function acquires from the server all the rows returned
by the query and stores them in the client. The second way is for the client to initiate a row-by-row
result set retrieval by calling mysql_use_result(). This function initializes the retrieval, but does not
actually get any rows from the server.
In both cases, you access rows by calling mysql_fetch_row(). With mysql_store_result(),
mysql_fetch_row()
mysql_use_result(),
about the size of the data in each row is available by calling mysql_fetch_lengths().
After you are done with a result set, call
The two retrieval mechanisms are complementary. Choose the approach that is most appropriate for
each client application. In practice, clients tend to use
An advantage of
mysql_store_result()
client, you not only can access rows sequentially, you can move back and forth in the result set using
mysql_data_seek()
You can also find out how many rows there are by calling mysql_num_rows(). On the other hand,
the memory requirements for
are more likely to encounter out-of-memory conditions.
An advantage of
mysql_use_result()
set because it maintains only one row at a time (and because there is less allocation overhead,
mysql_use_result()
to avoid tying up the server, you don't have random access to rows within the result set (you can only
access rows sequentially), and you don't know how many rows are in the result set until you have
retrieved them all. Furthermore, you must retrieve all the rows even if you determine in mid-retrieval
that you've found the information you were looking for.
The API makes it possible for clients to respond appropriately to statements (retrieving rows
only as necessary) without knowing whether the statement is a SELECT. You can do this by
calling
mysql_store_result()
If the result set call succeeds, the statement was a
result set call fails, call
to be expected. If
mysql_field_count()
(indicating that it was an INSERT, UPDATE, DELETE, and so forth), and was not expected to
return rows. If
mysql_field_count()
but didn't. This indicates that the statement was a
mysql_field_count()
Both
mysql_store_result()
the fields that make up the result set (the number of fields, their names and types, and so forth). You
can access field information sequentially within the row by calling
or by field number within the row by calling mysql_fetch_field_direct(). The current field
cursor position may be changed by calling mysql_field_seek(). Setting the field cursor affects
subsequent calls to mysql_fetch_field(). You can also get information for fields all at once by
calling mysql_fetch_fields().
For detecting and reporting errors, MySQL provides access to error information by means of the
and
mysql_errno()
C API Function Overview
query (for example, INSERT, UPDATE, DELETE), you can find out how many
statements.)
SELECT
accesses rows that have previously been fetched from the server. With
mysql_fetch_row()
mysql_free_result()
is that because the rows have all been fetched to the
or
mysql_row_seek()
mysql_store_result()
is that the client requires less memory for the result
can be faster). Disadvantages are that you must process each row quickly
after each
mysql_field_count()
returns zero, the statement returned no data
is nonzero, the statement should have returned rows,
for an example of how this can be done.
and
mysql_use_result()
functions. These return the error code or error message for
mysql_error()
2143
actually retrieves the row from the server. Information
to free the memory used for it.
mysql_store_result()
to change the current row position within the result set.
may be very high for large result sets and you
(or mysql_real_query()).
mysql_query()
and you can read the rows. If the
SELECT
to determine whether a result was actually
that failed. See the description for
SELECT
enable you to obtain information about
mysql_fetch_field()
more commonly.
repeatedly,

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents