Name

mysql_affected_rows( )

Synopsis

my_ulonglong mysql_affected_rows(MYSQL *mysql)

This returns the number of rows affected by the most recent query for the current session. This function is meaningful only for INSERT, UPDATE, and DELETE statements. For SQL statements that don’t affect rows (e.g., SELECT), this function will return 0. For errors, it will return -1.

...
mysql_query(mysql,"UPDATE workreq
                    SET tech_person_id = '1015'
                    WHERE tech_person_id = '1012'");
my_ulonglong chg = mysql_affected_rows(mysql);
printf("Number of requests reassigned: %ul \n", chg);
...

In this example, an UPDATE statement is issued and the number of rows changed is extracted with the function and stored in the chg variable, which is then printed. For REPLACE statements, rows that are replaced are counted twice: once for the deletion and once for the insertion.

Get MySQL in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.