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..

$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
$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..?

You can try this it will surely help you.

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


Thank you

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++;
}

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.