PHP mysql_affected_rows() ফাংশন

সংজ্ঞা ও ব্যবহার

mysql_affected_rows() ফাংশন অন্তিম একবার কাজ করা MySQL কোয়ার্সির প্রভাবিত রেকর্ড সারির সংখ্যা ফিরিয়ে দেয়。

গঠনশৈলী

mysql_affected_rows(link_identifier)
পারামিটার বর্ণনা
link_identifier অপরিহার্য। MySQL-এর সংযুক্তি পরিচিতাকরণ। যদি কোনো পরিচিতাকরণ না দেওয়া হয়, তাহলে ডিফল্টভাবে সর্বশেষ যে সংযুক্তির কথা বলা হবে。 mysql_connect() খুলা সংযুক্তি mysql_connect() সংযুক্তি গড়ে তোলুন এবং তা ব্যবহার করুন। যদি কোনো দুর্ঘটনা ঘটে, কোনো সংযুক্তি পাওয়া যায় না বা সংযুক্তি গড়ে তোলা যায় না, তাহলে সিস্টেম একটি E_WARNING স্তরের নোটিশ প্রদান করবে。

ব্যাখ্যা

সর্বশেষ সংযুক্তির সাথে link_identifier সংযুক্তিকরা INSERT, UPDATE বা DELETE কোয়ার্সির প্রভাবিত রেকর্ড সারির সংখ্যা。

Returns the value

Returns the number of affected rows if successful, and -1 if the last query fails.

If the last operation is a DELETE query without any conditions (WHERE), all records in the table will be deleted, but the return value of this function was 0 before version 4.1.2.

When using an UPDATE query, MySQL will not update the column if the original value and the new value are the same. This makes the return value of the mysql_affected_rows() function not necessarily the number of records that match the query conditions, but only the number of truly modified records will be returned.

The REPLACE statement first deletes records with the same primary key, then inserts a new record. The function returns the number of deleted records plus the number of inserted records.

Example

<?php
$con = mysql_connect("localhost","mysql_user","mysql_pwd");
if (!$con)
  {
  die("Could not connect: " . mysql_error());
  }
mysql_select_db("mydb");
mysql_query("DELETE FROM mytable WHERE id < 5");
$rc = mysql_affected_rows();;
echo "Records deleted: " . $rc;
mysql_close($con);
?>

Output:

Records deleted: 4