20.4.1 mysql_affected_rows()

my_ulonglong mysql_affected_rows(MYSQL *mysql)

20.4.1.1 Description

Returns the number of rows affected (changed) by the last UPDATE, DELETE or INSERT query. May be called immediately after mysql_query() for UPDATE, DELETE or INSERT statements. For SELECT statements, mysql_affected_rows() works like mysql_num_rows().

mysql_affected_rows() is currently implemented as a macro.

20.4.1.2 Return values

An integer greater than zero indicates the number of rows affected or retrieved. Zero indicates that no records matched the WHERE clause in the query or that no query has yet been executed. -1 indicates that the query returned an error or that, for a SELECT query, mysql_affected_rows() was called prior to calling mysql_store_result().

20.4.1.3 Errors

None.

20.4.1.4 Example

mysql_query(&mysql,"UPDATE products SET cost=cost*1.25 WHERE group=10");
printf("%d products updated",mysql_affected_rows(&mysql));