casualventures Posted April 30, 2011 Share Posted April 30, 2011 So when I execute this it'll go for about 130k rows then give a 500 error. Any ideas how to avoid this and get it to complete? $i=10000000; while($i<=99999999) { $public = $i; $value = rand(10000000, 99999999); mysql_query("INSERT INTO yummy_table (public, value) VALUES('$public', '$value' ) ") or die(mysql_error()); $i++; } echo "done"; Quote Link to comment https://forums.phpfreaks.com/topic/235153-insert-data-into-100-million-rows-without-500-error/ Share on other sites More sharing options...
trq Posted April 30, 2011 Share Posted April 30, 2011 Any ideas how to avoid this and get it to complete? Is there a particular reason your executing this script via a web server instead of just scripting it behind the scenes? Quote Link to comment https://forums.phpfreaks.com/topic/235153-insert-data-into-100-million-rows-without-500-error/#findComment-1208536 Share on other sites More sharing options...
casualventures Posted April 30, 2011 Author Share Posted April 30, 2011 Is there a particular reason your executing this script via a web server instead of just scripting it behind the scenes? Because it needs to happen when a web app is getting installed via the browser. Is there a different way you would suggest I go about it? Quote Link to comment https://forums.phpfreaks.com/topic/235153-insert-data-into-100-million-rows-without-500-error/#findComment-1208830 Share on other sites More sharing options...
PFMaBiSmAd Posted May 1, 2011 Share Posted May 1, 2011 Why wouldn't you just generate each row as you need it? Add a row with the next public value with a generated random value? The result will be the same. To get your existing code to operate several times faster would require that you use a multi-value insert query - INSERT INTO yummy_table (public, value) VALUES (x,y),(),(),(),... You would build a query string with as many (x,y) values as you can (there is a limit to the size of each query string.) By putting 10k - 100k values in each query, you will reduce the number of queries. Quote Link to comment https://forums.phpfreaks.com/topic/235153-insert-data-into-100-million-rows-without-500-error/#findComment-1208837 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.