php mysql_affected_rows
The mysql_affected_rows function in PHP is used to get the number of affected rows by the last INSERT, UPDATE, or DELETE query executed with the MySQL connection.
It takes the MySQL connection as a parameter and returns the number of affected rows as an integer.
Here's an example usage:
$conn = mysql_connect('localhost', 'username', 'password');
mysql_select_db('database_name', $conn);
$query = "UPDATE users SET status = 'active' WHERE id = 1";
mysql_query($query, $conn);
$affectedRows = mysql_affected_rows($conn);
echo "Number of affected rows: " . $affectedRows;
In this example, we connect to the MySQL server, select the database, and then execute an UPDATE query to update the status of a user. After executing the query, we use the mysql_affected_rows function to get the number of affected rows and then echo it.
Note that the mysql_affected_rows function should be used immediately after executing an INSERT, UPDATE, or DELETE query, as it only returns the number of affected rows for the most recent query. If you need to get the number of affected rows for multiple queries, you should call this function after each query.
原文地址: http://www.cveoy.top/t/topic/jfPA 著作权归作者所有。请勿转载和采集!