SQL PHP HTML ASP JavaScript articles and free scripts to download
 

Rowcount to get number of rows changed or affected by Query

WE can use rowcount() to know number of rows or records affected by the latest sql statement involving any Delete , update , insert command. This function is to be used immediately after the sql execute command. This function works similar to mysql_affected_rows function

WE will learn some examples on how to use this in our pdo example table. Download the dump file of pdo_admin table at the end of the tutorial.
$count=$dbo->prepare("update  pdo_admin set status='T' "); 
$count=$dbo->prepare("delete from pdo_admin where status='F'");
$count->execute();
$no=$count->rowCount();
echo " No of records = ".$no;  
Output will show number of records updated or deleted from the table ( based on which line is executed )
No of records = 7
Same way let us try with one delete command
$count=$dbo->prepare("delete from pdo_admin where status='F'");
$count->execute();
$no=$count->rowCount();
echo " No of records = ".$no;
The output will show us number of records deleted from the pdo_admin table.
Same way you can do for insert command.

rowcount with Select Command

Usually rowcount works with delete, update and insert commands but it as well works with select command in MySQL database. This returns total number of records present in the table . Here is an example of how it works.

$count=$dbo->prepare("select * from pdo_admin ");
$count->execute();
$no=$count->rowCount();
echo " No of records = ".$no;

Above code returns

No of records = 10

Download MySQL dump file to create your table to use this tutorial


khan02-12-2012
can u send me file for that plzzz
Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked

Join Our Email List
Email:  
For Email Newsletters you can trust
PDO
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2013 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer