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

How to use php mysqli_affected_rows function

藏色散人
Release: 2023-02-22 19:16:01
Original
2782 people have browsed it

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);
Copy after login

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); 
?>
Copy after login

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!

Related labels:
php
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template