What is the difference between mysqli_affected_rows and mysqli_num_rows?

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?


num_rows tells you how many rows there are in the result set you just selected with a SELECT query. affected_rows tells you how many rows where affected by an INSERT, UPDATE, REPLACE or DELETE query. The difference is obvious:

$resultSet = mysqli_query($c, 'SELECT ...'); echo mysqli_num_rows($resultSet);

SELECT result set goes into num_rows.

mysqli_query($c, 'UPDATE ...'); echo mysqli_affected_rows($c);

No result set, no num_rows.


mysql_affect_rows counts on how many rows your UPDATE/INSERT query was used and mysql_num_rows counts how many rows your SELECT statement found


  • Thread Synchronization with IntentService
  • const char **a = {“string1”,“string2”} and pointer arithametic
  • Gradle - How to detect --debug flag from command line?
  • Prevent Tomcat from caching request during starup
  • Jquery Knockout: ko.computed() vs classic function?
  • what makes a request a new request in asp.net C#
  • SAXReader not re-ecape characters
  • Ember.js model to be organised as a tree structure
  • Web.config system.webserver errors
  • Check for zero lines output from command over SSH
  • nonblocking BIO_do_connect blocked when there is no internet connected
  • xtable package: Skipping some rows in the output
  • Xcode 4 NSLog Macro link in Xcode 3
  • Make VS2015 use angular-cli ng at build time in a .NET project
  • Can you perform a UNION without a subquery in SQLAlchemy?
  • MailKit: The IMAP server replied to the 'EXAMINE' command with a 'BAD' response
  • Is it possible to access block's scope in method?
  • PostgreSQL Query without WHERE only ORDER BY and LIMIT doesn't use index
  • Meteor: Do Something On Email Verification Confirmation
  • Google Custom Search with transparent background
  • Checking free space on FTP server
  • Adding a button at the bottom of a table view
  • Getting last autonumber in access
  • Display Images one by one with next and previous functionality
  • Function pointer “assignment from incompatible pointer type” only when using vararg ellipsis
  • Delete MySQLi record without showing the id in the URL
  • Why winpcap requires both .lib and .dll to run?
  • GridView Sorting works once only
  • R: gsub and capture
  • 0x202A in filename: Why?
  • AT Commands to Send SMS not working in Windows 8.1
  • retrieve vertices with no linked edge in arangodb
  • using conditional logic : check if record exists; if it does, update it, if not, create it
  • SQL merge duplicate rows and join values that are different
  • How to set the response of a form post action to a iframe source?
  • Understanding cpu registers
  • File not found error Google Drive API
  • Are Kotlin's Float, Int etc optimised to built-in types in the JVM? [duplicate]
  • Add sale price programmatically to product variations
  • unknown Exception android