title: MYSQL: Batch insert/update statements in single query
body: <p>I need to do <strong>batch</strong> MYSQL insert/updates. I got batch insert statement to work, but when the insert comes as multiple one liners it does not.. Similarly I have not been able to generate a batch update. Please see examples below.</p>
  
  <p><strong><em>Batch</em> insert statement works</strong></p>
  
  <pre><code>$sql = "INSERT INTO `test` (`somefield`) VALUES ('test', 'test');";
  db::statement($sql);
  </code></pre>
  
  <p><strong><em>Multiple</em> separate insert statements <em>NOT</em> working</strong></p>
  
  <pre><code>$sql = "INSERT INTO `test` (`somefield`) VALUES ('test'); INSERT INTO `test` (`somefield`) VALUES ('test');";
  db::statement($sql);
  </code></pre>
  
  <blockquote>
    <p>SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSERT INTO <code>test</code> (<code>somefield</code>) VALUES ('test')' at line 1 (SQL: INSERT INTO <code>test</code> (<code>somefield</code>) VALUES ('test'); INSERT INTO <code>test</code> (<code>somefield</code>) VALUES ('test');)</p>
  </blockquote>
  
  <p><strong>Batch update statement not working</strong></p>
  
  <pre><code>$sql = "INSERT INTO 'flights' (`id`, `airline`) VALUES ('142832', 'BA') ON DUPLICATE KEY UPDATE `airline`=VALUES(`airline`);"
  db::statement($sql);
  </code></pre>
  
  <blockquote>
    <p>1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''flights' (<code>id</code>, <code>airline</code>) VALUES ('142832', 'BA') ON DUPLICATE KEY UP' at line 1</p>
  </blockquote>
  
  <p><strong>Reviewed multiple Stackoverflow posts - but I am getting something wrong</strong></p>
  
  <p>Multiple insert statements - <a href="https://stackoverflow.com/questions/9162671/multiple-sql-update-statements-in-single-query">Multiple SQL Update Statements in single query</a></p>
  
  <p>Batch update statement - <a href="https://stackoverflow.com/questions/3432/multiple-updates-in-mysql">Multiple Updates in MySQL</a></p>
  
  <p>Would appreciate help on this - thanks!</p>