Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am just newbie to the MySQL.I want to know what is the main differences in between mysql num rows and mysql affected num rows?Any example or references will be highly appreciable.

share|improve this question
up vote 1 down vote accepted

Here's mysql_num_rows:

int mysql_num_rows ( resource $result ) 

Retrieves the number of rows from a result set. This command is only valid for statements like SELECT or SHOW that return an actual result set. To retrieve the number of rows affected by a INSERT, UPDATE, REPLACE or DELETE query, use mysql_affected_rows().

And here's mysql_affected_rows:

int mysql_affected_rows ([ resource $link_identifier = NULL ] )

Get the number of affected rows by the last INSERT, UPDATE, REPLACE or DELETE query associated with link_identifier.

Notice that the input types are different: the first wants a result set, from which it counts the number of rows returned; the second wants a db handle. That makes sense, though, because when you INSERT (or UPDATE, DELETE, REPLACE) a row, you typically don't want a result set -- you just want to know if it succeeded or failed, or how many rows it updated/replaced/deleted.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.