PHP mysqli_affected_rows number of action rows return value _php Tutorial

Source: Internet
Author: User
This article to give your classmates about the Mysqli_affected_rows function in PHP return value, there is a need to know the friend can refer to.

The number of rows affected by the update operation in Mysqli can have two return forms:

1. Returns the number of matching rows

2. Returns the number of rows affected

By default, the value returned by Mysqli_affected_rows is the number of rows affected, and if we need to return a matching number of rows, you can use the Mysqli_real_connect function to initialize the database connection and add the flag parameter bit to the function:


Mysqli_client_found_rows return number of matched rows, not the number of affected rows


Normal format:
int mysqli_affected_rows (mysqli link)
OOP format:
Class Mysqli {
int Affected_rows
}
Take a look at the following example:
Normal mode

The code is as follows Copy Code

$link = Mysqli_connect ("localhost", "My_user", "My_password", "World");

if (! $link) {
printf ("Can ' t connect to localhost. Error:%sn ", Mysqli_connect_error ());
Exit ();
}

/* Insert rows */
Mysqli_query ($link, "CREATE TABLE Language select * from Countrylanguage");
printf ("Affected Rows (INSERT):%dn", Mysqli_affected_rows ($link));

Mysqli_query ($link, "ALTER TABLE Language ADD Status int default 0″);

/* Update rows */
Mysqli_query ($link, "UPDATE Language SET status=1 WHERE Percentage > 50″);
printf ("Affected Rows (UPDATE):%dn", Mysqli_affected_rows ($link));

/* Delete rows */
Mysqli_query ($link, "DELETE from Language WHERE Percentage < 50″);
printf ("Affected Rows (DELETE):%dn", Mysqli_affected_rows ($link));

/* Select all rows */
$result = Mysqli_query ($link, "Select CountryCode from Language");
printf ("Affected Rows (Select):%dn", Mysqli_affected_rows ($link));

Mysqli_free_result ($result);

/* Delete Table Language */
Mysqli_query ($link, "DROP TABLE Language");

/* Close Connection */
Mysqli_close ($link);
?>


OOP mode

The code is as follows Copy Code

$mysqli = new Mysqli ("localhost", "My_user", "My_password", "World");

/* Check connection */
if (Mysqli_connect_errno ()) {
printf ("Connect failed:%sn", Mysqli_connect_error ());
Exit ();
}

/* Insert rows */
$mysqli->query ("CREATE TABLE Language select * from Countrylanguage");
printf ("Affected Rows (INSERT):%dn", $mysqli->affected_rows);

$mysqli->query ("ALTER TABLE Language ADD Status int default 0″);

/* Update rows */
$mysqli->query ("UPDATE Language SET status=1 WHERE Percentage > 50″);
printf ("Affected Rows (UPDATE):%dn", $mysqli->affected_rows);

/* Delete rows */
$mysqli->query ("DELETE from Language WHERE Percentage < 50″);
printf ("Affected Rows (DELETE):%dn", $mysqli->affected_rows);

/* Select all rows */
$result = $mysqli->query ("Select CountryCode from Language");
printf ("Affected Rows (Select):%dn", $mysqli->affected_rows);

$result->close ();

/* Delete Table Language */
$mysqli->query ("DROP TABLE Language");

/* Close Connection */
$mysqli->close ();
?>

http://www.bkjia.com/PHPjc/630691.html www.bkjia.com true http://www.bkjia.com/PHPjc/630691.html techarticle This article to give your classmates about the Mysqli_affected_rows function in PHP return value, there is a need to know the friend can refer to. The number of rows affected by the update operation in MYSQLI can have two kinds of return ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.