The PHP docs for mysqli_num_rows says
Returns the number of rows in the result set.
The PHP docs for mysqli_affected_rows says
Returns the number of rows affected by the last INSERT, UPDATE, REPLACE or DELETE query.
_num_rows is called on a result, and _affected_rows is called on a connection. Since I think they do the same thing(correct this assumption if I'm wrong), I'm wondering whether one works better than the other, and which situations would call for which function.
Aren't number of rows affected and number of rows in the result set synonymous?
mysql_affect_rows
counts on how many rows yourUPDATE/INSERT
query was used andmysql_num_rows
counts how many rows yourSELECT
statement foundnum_rows
tells you how many rows there are in the result set you just selected with aSELECT
query.affected_rows
tells you how many rows where affected by anINSERT
,UPDATE
,REPLACE
orDELETE
query. The difference is obvious:SELECT
result set goes intonum_rows
.No result set, no
num_rows
.