PHP mysqli_affected_rows() Function
In this chapter you will learn:
- Definition for PHP mysqli_affected_rows() Function
- Syntax for PHP mysqli_affected_rows() Function
- Parameter for PHP mysqli_affected_rows() Function
- Return for PHP mysqli_affected_rows() Function
- Example - prints out affected rows from different queries
Definition
The mysqli_affected_rows() function returns the number of affected rows in the previous SELECT, INSERT, UPDATE, REPLACE, or DELETE query.
Syntax
PHP mysqli_affected_rows() Function has the following syntax.
mysqli_affected_rows(connection);
Parameter
Parameter | Is Required | Description |
---|---|---|
connection | Required. | MySQL connection |
Return
It returns
- an integer > 0 indicating the number of rows affected.
- 0 indicates that no records where affected.
- -1 indicates that the query returned an error.
Example
The following code prints out affected rows from different queries.
<?php/*from j a v a 2s .c o m*/
$con=mysqli_connect("localhost","my_user","my_password","my_db");
if (mysqli_connect_errno($con)){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_query($con,"SELECT * FROM emp");
echo "Affected rows: " . mysqli_affected_rows($con);
mysqli_close($con);
?>
Next chapter...
What you will learn in the next chapter:
- Definition for PHP mysqli_autocommit() Function
- Syntax for PHP mysqli_autocommit() Function
- Parameter for PHP mysqli_autocommit() Function
- Return for PHP mysqli_autocommit() Function
- Related functions
- Example - turns off auto-committing, make some queries, then commit the queries
Home » PHP Tutorial » PHP MySQLi Functions