PHP mysqli_affected_rows() 函数
PHP mysqli_affected_rows() 函数
实例
从不同的查询中输出所影响记录行数:
<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// 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);
?>
$con=mysqli_connect("localhost","my_user","my_password","my_db");
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// 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);
?>
定义和用法
mysqli_affected_rows() 函数返回前一次 MySQL 操作(SELECT、INSERT、UPDATE、REPLACE、DELETE)所影响的记录行数。
语法
mysqli_affected_rows(connection);
参数 | 描述 |
---|---|
connection | 必需。规定要使用的 MySQL 连接。 |
技术细节
返回值: | 一个 > 0 的整数表示所影响的记录行数。0 表示没有受影响的记录。-1 表示查询返回错误。 |
---|---|
PHP 版本: | 5+ |
PHP MySQLi 参考手册