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