(PHP 5)

Mysqliaffectedrows returns -1. A trillion rows per second ingest and query processing. Rowstores & Columnstores available. Get peak performance in the cloud, on premise, or with Kubernetes. Mysqliaffectedrows returns the number of rows which were changed as a result of the last query. Mysqlinumrows returns the number of rows in the array/resource (i.e. The query result) returned by the query. Even if mysqlinumrows may work for counting affected rows, it's probably not a good idea to do.


(no version information, might be only in CVS)

mysqli_stmt->affected_rows -- Returns the total number of rows changed, deleted, or inserted by the last executed statement


Procedural style :

int mysqli_stmt_affected_rows ( mysqli_stmt stmt )

Object oriented style (property):

class mysqli_stmt {
int affected_rows

mysqli_stmt_affected_rows() returns the number of rows affected by INSERT, UPDATE, or DELETE query. If the last query was invalid, this function will return -1.

The mysqli_stmt_affected_rows() function only works with queries which update a table. In order to return the number of rows from a SELECT query, use the mysqli_stmt_num_rows() function instead.

Return Values

An integer greater than zero indicates the number of rows affected or retrieved. Zero indicates that no records where updated for an UPDATE/DELETE statement, no rows matched the WHERE clause in the query or that no query has yet been executed. -1 indicates that the query has returned an error.

Note: If the number of affected rows is greater than maximal PHP int value, the number of affected rows will be returned as a string value.

See Also

Mysqli_affected_rows in php

mysqli_stmt_num_rows() and mysqli_prepare().


  • PHP Tutorial
  • Advanced PHP
  • PHP Form Examples
  • PHP login Examples
  • PHP AJAX Examples
  • PHP XML Example

Mysqli_affected_rows() Expects Parameter 1

  • PHP Frame Works
  • PHP Design Patterns
  • PHP Function Reference
  • PHP Useful Resources
  • Selected Reading

Definition and Usage

Php projects with source code download. The mysqli_stmt_affected_rows() function returns the number of rows affected (changed, deleted, inserted) by the recently executed statement.

This function works fine only if invoked after INSERT, UPDATE, or DELETE statements. If you need to know the number of rows affected by the SELECT query you need to use the mysqli_stmt_num_rows() function.



Sr.NoParameter & Description


This is an object representing a statement executing a SQL query.

Return Values

PHP mysqli_stmt_affected_rows() function returns an integer value indicating the number of rows affected by the previous (INSERT, UPDATE, REPLACE or DELETE) operation.

If the statement has an error this function returns -1. If there are no affected rows, this function returns 0.

PHP Version

This function was first introduced in PHP Version 5 and works works in all the later versions.



Assume we have created a table named employee in the MySQL database with the following contents $minus;

Following example demonstrates the usage of the mysqli_stmt_affected_rows() function (in procedural style) −

This will produce following result −


In object oriented style the syntax of this function is $con->affected_rows; Following is the example of this function in object oriented style $minus;

This will produce following result −


Mysqli_affected_rows Not Working

Let's check the return values of this if the query does not effect any rows −


Mysqli_affected_rows Returns Negative

This will produce following result −