0

Hello Friends..

i m inserting near about 20000 in db at a time.. i jst want to know how can i get the number of inserted rows and time taken to done that..!!!

Thanks in advance..

4
Contributors
6
Replies
10
Views
7 Years
Discussion Span
Last Post by sam023
0
$time_start = microtime(true);
$r=mysql_query($sql);
sleep(1); //let the server relax after such a big query.
$time_end = microtime(true);

$time_for_mysqlquery = $time_end - $time_start;
$number_of_rows=mysql_num_rows($r); //works only for SELECT in mysql query
0
$time_start = microtime(true);
$r=mysql_query($sql);
sleep(1); //let the server relax after such a big query.
$time_end = microtime(true);

$time_for_mysqlquery = $time_end - $time_start;
$number_of_rows=mysql_num_rows($r); //works only for SELECT in mysql query

Sorry for late reply... time script runs well.. but the number of rows at that time.. i thnk tht cant be get by mysql_num_rows. it will count all rows. i want number of rows inserted at tht particular time period.. mysql_effected_rows does this going to help..?

0

You can try this it will surely help you.

$total_records_affected=mysql_affected_rows($query);
echo $total_records_affected;


Thank you

Edited by prem2: n/a

1

Since every new record is a standalone INSERT query you might be better off counting manually by incrementing a variable?

$count = 0;
while(){
 mysql_query("INSERT into.......") or die(mysql_error());
 $count++;
}
0

Well if you are inserting and want to count then it is a little more tricky. Below is an example that may or may not work.

$time_start = microtime(true);
mysql_query($sql);
sleep(1); //let the server relax after such a big query.
$time_end = microtime(true);
 
$time_for_mysqlquery = $time_end - $time_start;
$number_of_rows=mysql_affected_rows(); //works only for INSERT in previous query

That is the theory behind it anyways. Basically mysql_affected_rows has no inputs unless you specified a linker for mysql_connect() in which case the linker for mysql connect would go between the brackets. Hope that helps.

0

Well if you are inserting and want to count then it is a little more tricky. Below is an example that may or may not work.

$time_start = microtime(true);
mysql_query($sql);
sleep(1); //let the server relax after such a big query.
$time_end = microtime(true);
 
$time_for_mysqlquery = $time_end - $time_start;
$number_of_rows=mysql_affected_rows(); //works only for INSERT in previous query

That is the theory behind it anyways. Basically mysql_affected_rows has no inputs unless you specified a linker for mysql_connect() in which case the linker for mysql connect would go between the brackets. Hope that helps.

Actually before inserting data i have run update command for three times... means mysql_effectef_rows will count tht also..

i thnk $counter is good Idea.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.