Table of Contents

Syntax

int mysql_affected_rows([resource $res])

(PHP 4, PHP 5)

$res The database connection resource that we want to use.
RETURNS Total number of rows affected by the last INSERT, UPDATE, or DELETE statement.

What it Does

This counts the total number of rows affected by the last INSERT, UPDATE, or DELETE statement. The $res parameter is optional. If not specified, the function will just use the last database resource opened by the script.

Example

// open the mysql resource
$res = mysql_connect($server, $user, $pass);
 
// insert a single row into tblState
mysql_query ('INSERT INTO tblState (\'California\')', $res);
 
// return the number of rows
$rows = mysql_affected_rows($res);
 
// close the mysql resource
mysql_close($res);