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:

    $insert = array();
      $insert[] = "('".md5(rand(0,1000))."')";

and then executing the query:

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

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

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

Good luck.