mysql_affected_rows

47 views

mysql_affected_rows() : Returns the number of affected rows in the previous MySQL operation.

Version :

(PHP 3, PHP 4, PHP 5)

Syntax :

int mysql_affected_rows ([ resource $link_identifier ] )

Description :
mysql_affected_rows() returns the number of rows affected by the last INSERT, UPDATE or DELETE query associated

with link_identifier.

This function returns the number of affected rows on success, or -1 if the last operation failed.

Example : Delete Query

<?php
$con = mysql_connect(”localhost”,”user”,”password”);
if (!$con)
  {
  die(”Could not con: ” . mysql_error());
  }
mysql_select_db(”mydb”);
mysql_query(”DELETE FROM mytable WHERE id < 8″);
$row = mysql_affected_rows();
echo “Records deleted: ” . $row;
mysql_close($con);
?>

The output of the code above could be:
Records deleted : 7

Example : Update Query

  1.  
  2. <?php
  3. $con= mysql_connect("localhost","user","password");
  4. if (!$con) {
  5. die("Could not connect:" . mysql_error());
  6. }
  7. mysql_query("UPDATE mytable SET used=1 WHERE id < 8");
  8.  
  9. echo "Updated records: ".$row;
  10.  
  11.  
  12. ?>
  13.  

The output of the code above could be:
Updated records : 7

  1.  
  2. <?
  3. function mysql_affected_rows($con = NULL)
  4.        {
  5.         $con = mysql_resolve_link($con);
  6.         return mysqli_affected_rows($con);
  7.        }
  8. ?>
  9.  



« Firefox 3.0.6 security issues mysql_change_user »
Posted on Wednesday, February 4th, 2009 at 4:54 pm under Mysql Functions | RSS 2.0 Feed

Post Comment

You must be logged in to post a comment.



ComputerEducationWorld.com All Rights Reserved © RSS | CBSE | Education Boards Of India | What is My IP?