Php/func mysqli affected rows
来自菜鸟教程
PHP mysqli受影响的_行函数
示例-面向对象的样式
从不同的查询返回受影响的行数:
<?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(); ?>
在底部查看程序样式的示例。
定义和用法
受影响的行/ mysqli_affected_rows()函数返回上一个SELECT,INSERT,UPDATE,REPLACE或DELETE查询中受影响的行数。
句法
面向对象的样式:
$mysqli -> affected_rows
程序风格:
mysqli_affected_rows(connection)
参数值
参数 | 描述 |
---|---|
connection | 需要。指定要使用的MySQL连接 |
技术细节
返回值: | 受影响的行数。-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); ?>