Home >Backend Development >PHP Tutorial >Detailed explanation of the mysqli_affected_rows() method in PHP

Detailed explanation of the mysqli_affected_rows() method in PHP

autoload
autoloadOriginal
2021-04-29 13:45:553904browse

    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);
  • $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();
}

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);
输出:数据库中的受影响.7

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!

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