返回不同查询中受影响的行数:
<?php
$mysqli = new mysqli("localhost","my_user","my_password","my_db");
if ($mysqli -> connect_errno) {
echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
exit();
}
// Perform queries and print out affected rows
$mysqli -> query("SELECT * FROM Persons");
echo "Affected rows: " . $mysqli -> affected_rows;
$mysqli -> query("DELETE FROM Persons WHERE Age>32");
echo "Affected rows: " . $mysqli -> affected_rows;
$mysqli -> close();
?>
查看底部的程序样式示例。
affected_rows / mysqli_affected_rows() 函数返回先前 SELECT、INSERT、UPDATE、REPLACE 或 DELETE 查询中受影响的行数。
$mysqli -> affected_rows
mysqli_affected_rows(
connection)
Parameter | Description |
---|---|
connection | Required. Specifies the MySQL connection to use |
返回值: | 受影响的行数。 -1表示查询返回错误 |
---|---|
PHP 版本: | 5+ |
返回不同查询中受影响的行数:
<?php
$con = mysqli_connect("localhost","my_user","my_password","my_db");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}
// Perform queries and print out affected rows
mysqli_query($con, "SELECT * FROM Persons");
echo "Affected rows: " . mysqli_affected_rows($con);
mysqli_query($con, "DELETE FROM Persons WHERE Age>32");
echo "Affected rows: " . mysqli_affected_rows($con);
mysqli_close($con);
?>
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!