mysqli::$affected_rows
(mysqli_affected_rows) Get the number of rows affected in previous MySQL operations
affected_rows
/ mysqli_affected_rows()
function returns the number of rows affected in the last SELECT, INSERT, UPDATE, REPLACE, or DELETE query.
Returns the number of rows affected in different queries:
<?php $mysqli = new mysqli ( "localhost" , "my_user" , "my_password" , "my_db" ) ; if ( $mysqli -> connect_errno ) { echo "Failed to connect to MySQL: " . $mysqli -> connect_error ; exit ( ) ; } // Execute the query and output the number of affected rows $mysqli -> query ( "SELECT * FROM Persons" ) ; echo "Affected rows: " . $mysqli -> affected_rows ; $mysqli -> query ( "DELETE FROM Persons WHERE Age>32" ) ; echo "Affected rows: " . $mysqli -> affected_rows ; $mysqli -> close ( ) ; ?>
Returns the number of rows affected in different queries:
<?php $con = mysqli_connect ( "localhost" , "my_user" , "my_password" , "my_db" ) ; if ( mysqli_connect_errno ( ) ) { echo "Failed to connect to MySQL: " . mysqli_connect_error ( ) ; exit ( ) ; } // Execute the query and output the number of affected rows mysqli_query ( $con , "SELECT * FROM Persons" ) ; echo "Affected rows: " . mysqli_affected_rows ( $con ) ; mysqli_query ( $con , "DELETE FROM Persons WHERE Age>32" ) ; echo "Affected rows: " . mysqli_affected_rows ( $con ) ; mysqli_close ( $con ) ; ?>