PHP mysqli_affected_rows () function
Examples
Record the number of rows in the query output different from the implications:
<? php
// Assumes that the database username: root, password: 123456, database: w3big
$ con = mysqli_connect ( "localhost" , "root", "123456", "w3big");
if (mysqli_connect_errno ($ con))
{
echo "MySQL connection failed:" mysqli_connect_error ();.
}
// Execute the query and output the number of affected rows
mysqli_query ($ con, "SELECT * FROM websites");
echo "the number of affected rows:" mysqli_affected_rows ($ con); .
echo "<br>";
mysqli_query ($ con, "DELETE FROM websites WHERE alexa> 1000");
echo "the number of affected rows:" mysqli_affected_rows ($ con); .
mysqli_close ($ con);
?>
// Assumes that the database username: root, password: 123456, database: w3big
$ con = mysqli_connect ( "localhost" , "root", "123456", "w3big");
if (mysqli_connect_errno ($ con))
{
echo "MySQL connection failed:" mysqli_connect_error ();.
}
// Execute the query and output the number of affected rows
mysqli_query ($ con, "SELECT * FROM websites");
echo "the number of affected rows:" mysqli_affected_rows ($ con); .
echo "<br>";
mysqli_query ($ con, "DELETE FROM websites WHERE alexa> 1000");
echo "the number of affected rows:" mysqli_affected_rows ($ con); .
mysqli_close ($ con);
?>
Definition and Usage
mysqli_affected_rows () function returns the number of rows before MySQL operation (SELECT, INSERT, UPDATE, REPLACE, DELETE) affected.
grammar
mysqli_affected_rows( connection ) ;
参数 | 描述 |
---|---|
connection | 必需。规定要使用的 MySQL 连接。 |
technical details
return value: | A> 0 integer representing the number of rows affected. 0 means no records affected. -1 Indicates that the query returns an error. |
---|---|
PHP version: | 5+ |
PHP MySQLi Reference Manual