Home >Backend Development >PHP Problem >How to use php mysqli_affected_rows function

How to use php mysqli_affected_rows function

藏色散人
藏色散人Original
2019-05-26 11:07:272716browse

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).

How to use php mysqli_affected_rows function

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn