Monday, June 25, 2012

Multiple mysql insert quiery

i was trying to insert a lot ( 1.000.000 ) values into single table with single query, because inserting each value takes much longer time.

table looks like:

id , value

so solution is to create array with php of the values:

code:
    $insert = array();
    for($i=0;$i<=950000;$i++)
    {
      $insert[] = "('".md5(rand(0,1000))."')";
    }

and then executing the query:

$sql = "INSERT INTO `skelbimai` ( `value` ) VALUES ".implode(",",$insert)." ";
ALSO

You might have problem with time limit. so i set up this limit:

set_time_limit(1800);
Also you might have problem with memory_limit, so use it:
ini_set('memory_limit', '150M'); 

Good luck.