PHP Mysql multiple inserts (big dataset) -


i have been running relatively simple script, tends lock database.

each time lookup value inserted, checked against make sure isnt inserted again.

this works on small data sets (<50k), has issues large data sets (>2m). appreciated.

$insertcounter = 20; $matchcounter = 200;  $insertindex = 0; $sqlinsert = 'insert `database` (`lookup_value`, `timestamp`, `source`) values '; $matchindex = 0; $resetcount = 0; $indexcounter = 0;  foreach ($matches $lookup) {     $sqlselect = 'select `id` `database` `lookup_value` = \'' . $lookup . '\'';     $qexisting = executesql($sqlselect);      if (mysql_num_rows($qexisting) == 0) {         $insertindex += 1;         $sqlinsert .= '(\'' . strtolower($lookup) . '\', \'' . date('y-m-d h:i:s') . '\', \'database\'), ';          if ($insertindex >= $insertcounter) {             $sqlinsert = substr($sqlinsert, 0, strlen($sqlinsert) - 2);             executesqlnoresult($sqlinsert);                  echo '<p><strong>' . date('y-m-d h:i:s') . '</strong><br />' . $sqlinsert . '</p>';              $sqlinsert = 'insert `database` (`lookup_value`, `timestamp`, `source`) values ';             $insertindex = 0;         }     }      mysql_free_result($qexisting);     $matchindex += 1;     $indexcounter += 1;      if ($matchindex > $matchcounter) {         $resetcount += 1;         $matchindex = 0;         echo '<p>(' . $indexcounter . ', reset no.' . $resetcount . ') counter reached, resetting.</p>';     } } 

how adding unique index lookup_value field , using insert ignore statement?


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -