hello friends..
i have a excel file which has more than 20000 rows..!!`when i upload the file i got this error ' MySQL server has gone away '

even i increase the maximum excution time to 3000..and
and memory limit to 512.!!

i just want to know how many rows it can insert or read..so tht i can break the excel sheet according to it..

Recommended Answers

All 4 Replies

Although you increased the memory limit and execution time I bet you didn't do the same for mysql. To do such a processing job you would need to change the memory limit and execution time for both mysql and php. Sounds like you only did it for php. Not sure how to do it for mysql though. I am guessing the memory limit for mysql would be 32MB so if you closed the connection and reopened the connection every so often in the loop then that should solve your problem. For example:

<?php
$link=mysql_connect('localhost','root','');
mysql_select_db('database',$link);

for ($i=0;$i<100000;$i++) { //change condition
if (($i/500)==round($i/500)) {
    mysql_close($link);
    sleep(2); //let cpu decrease
    $link=mysql_connect('localhost','root','');
    mysql_select_db('database',$link);
    }
//do stuff in here
}

The above is a rough idea of what it should look like and hope it helps.

I assume that you problem in file uploading through html file upload method.
If so,,
Try to upload huge files through ftp methods.There are codes for the ftp methods.This will be a better solution for your problem.

Although you increased the memory limit and execution time I bet you didn't do the same for mysql. To do such a processing job you would need to change the memory limit and execution time for both mysql and php. Sounds like you only did it for php. Not sure how to do it for mysql though. I am guessing the memory limit for mysql would be 32MB so if you closed the connection and reopened the connection every so often in the loop then that should solve your problem. For example:

<?php
$link=mysql_connect('localhost','root','');
mysql_select_db('database',$link);

for ($i=0;$i<100000;$i++) { //change condition
if (($i/500)==round($i/500)) {
    mysql_close($link);
    sleep(2); //let cpu decrease
    $link=mysql_connect('localhost','root','');
    mysql_select_db('database',$link);
    }
//do stuff in here
}

The above is a rough idea of what it should look like and hope it helps.

Yes u r right.. i didnt increase memory limit for mysql.. nor i found any option to increase memory limit in my.ini

secondly, i want to know how many rows has been read in predfined time..!! how can i do that..??

Well the answer is you can send to mysql 32MB at a time. That is 33,554,432 characters/letters/digits. So make sure the length of all your mysql query's do not go beyond 32MB and re-establish the mysql connection just before 32MB has been breached.

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.