Detailed explanation of the mysqli_affected_rows() method in PHP

autoload
Release: 2023-04-09 22:36:02
Original
3874 people have browsed it

    Detailed explanation of the mysqli_affected_rows() method in PHP   php requires frequent connection to the database. mysqli is a way to connect to the database in php. After operating on the data, how to obtain the affected Record number, this article will take you to take a look at the mysqli_affected_rows() method. First, let’s understand the syntax of the mysqli_affected_rows() function.

mysqli_affected_rows($connection);
Copy after login
  • $connection:Required. Specifies the MySQL connection to use.

  • Return value: an integer > 0 indicating the number of record rows affected. 0 means there are no affected records. -1 means the query returned an error.

Code example:

1. Connect to the database

<?php
$servername="localhost";
$username="root";
$password="root123456";
$dbname="my_database";

$link = mysqli_connect($servername, $username, $password, $dbname);

/* check connection */
if (mysqli_connect_errno()) {
    printf("连接失败: %s\n", mysqli_connect_error());
    exit();
}
Copy after login

2.mysqli_affected_rows() uses

$sql="select * from fate";
if ($result = mysqli_query($link,$sql)) {
    $rows =mysqli_affected_rows($link);
    printf("数据库中的受影响.%d\n", $rows);
    mysqli_free_result($result);
}
mysqli_close($link);
Copy after login
输出:数据库中的受影响.7
Copy after login

Recommended: 2021 PHP Interview Questions Summary (Collection) 》《php video tutorial

The above is the detailed content of Detailed explanation of the mysqli_affected_rows() method in PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!