Do note that if you have turned off autocommit, and plan to do multiple actions before the commit, $affected_rows only works per statement. This means if, for example, you want to run multiple INSERT statements and tally all rows inserted after they are commited, a running counter will need to be implemented.
// start the count
$count = 0;
// turn off autocommit
$mysqli->autocommit(FALSE);
$mysqli->begin_transaction;
// insert a couple items
$query = "
INSERT INTO users ('id','username','email')
VALUES (1, 'userguy', 'userguy@mail.com'), (2, 'some_user', 'some_user@ymail.com')
";
$mysqli->query($query);
echo $mysqli->affected_rows; // 2 - correct
$count += $mysqli->affected_rows; // add to the count
// insert one more
$query = "
INSERT INTO users ('id','username','email')
VALUES (3, 'anotherone', 'anotherone@mail.com')
";
$mysqli->query($query);
$count += $mysqli->affected_rows;
// insert one more
$query = "
INSERT INTO users ('id','username','email')
VALUES (4, 'thefourth', 'thefourth@gmail.com')
";
$mysqli->query($query);
$count += $mysqli->affected_rows;
// commit these statements to the database
$mysqli->commit();
echo $mysqli->affected_rows; // 1 - only counts the last statement run
echo "Actual count: ".$count; // 4