title: PHP bulk insert foreach
body: <p>I have a curl script which reads the data from a remote source. Below is the current code:</p>
  
  <pre><code>function download_page($path){
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL,$path);
      curl_setopt($ch, CURLOPT_FAILONERROR,1);
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
      curl_setopt($ch, CURLOPT_TIMEOUT, 15);
      $retValue = curl_exec($ch);                      
      curl_close($ch);
      return $retValue;
  }
  $sXML = download_page('http://remotepage.php&amp;function=getItems&amp;count=100&amp;page=1');
  $oXML = new SimpleXMLElement($sXML);
  foreach($oXML-&gt;results-&gt;item-&gt;item as $oEntry){
      $insert_query = mysql_query("INSERT INTO tbl_item (first_name, last_name, date_added) VALUES ('" . $oEntry-&gt;firstname . "', '" . $oEntry-&gt;lastname . "', '" . date("Y-m-d H:i:s") . "')");
  }
  </code></pre>
  
  <p>The script works however is extremely slow to insert as I imagine its because its writing each individual record. The count variable is how many records returned for each page and the page variable is a simple page counter.</p>
  
  <p>I am wondering if there is a way to do a bulk insert statement to insert all 100 records at once.</p>
  
  <p>Thanks in advance.</p>