Home >Backend Development >PHP Problem >How to use php mysqli_affected_rows function
php The mysqli_affected_rows function is used to return the number of record rows affected by the previous MySQL operation (SELECT, INSERT, UPDATE, REPLACE, DELETE). Its syntax is mysqli_affected_rows(connection).
php How to use the mysqli_affected_rows function?
Definition and usage
mysqli_affected_rows( ) function returns the number of record rows affected by the previous MySQL operation (SELECT, INSERT, UPDATE, REPLACE, DELETE).
Syntax
mysqli_affected_rows(connection);
Parameters
connection Required. Specifies the MySQL connection to use.
Return value: An integer > 0 indicates the number of record rows affected. 0 means there are no affected records. -1 means the query returned an error.
PHP Version: 5
php mysqli_affected_rows function usage example
Output the number of affected record rows from different queries:
<?php // 假定数据库用户名:root,密码:123456,数据库:RUNOOB $con=mysqli_connect("localhost","root","123456","RUNOOB"); if (mysqli_connect_errno($con)) { echo "连接 MySQL 失败: " . mysqli_connect_error(); } // 执行查询并输出受影响的行数 mysqli_query($con,"SELECT * FROM websites"); echo "受影响的行数: " . mysqli_affected_rows($con); echo "<br>"; mysqli_query($con,"DELETE FROM websites WHERE alexa>1000"); echo "受影响的行数: " . mysqli_affected_rows($con); mysqli_close($con); ?>
The above is the detailed content of How to use php mysqli_affected_rows function. For more information, please follow other related articles on the PHP Chinese website!