title: MySQL transaction, rollback doesn't work, (PHP PDO)
body: <p>I have a loop that inserts data in two tables, in the first iteration of the loop the insert is succesfull, but in the second iteration the insert will fail.</p>
  
  <p>I have written the script so that if any of the iterations fail, the entire transaction should be rollbacked. However, this doesn't work.</p>
  
  <p>The first iteration (that succeeded) isn't rolled back...</p>
  
  <pre><code>&lt;?php
      include('model/dbcon.model.php');
  
      $languages = array('project_nl', 'project_en');
  
      DBCon::getCon()-&gt;beginTransaction();
  
      $rollback = true;
  
      foreach($languages as $language) {
          $Q = DBCon::getCon()-&gt;prepare('INSERT INTO `'.$language.'`(`id`, `name`, `description`, `big_image`) VALUES (:id,:name,:description,:big_image)');
          $Q-&gt;bindValue(':id', '1', PDO::PARAM_INT);
          $Q-&gt;bindValue(':name', 'test', PDO::PARAM_INT);
          $Q-&gt;bindValue(':description', 'test', PDO::PARAM_INT);
          $Q-&gt;bindValue(':big_image', 'test', PDO::PARAM_INT);
  
          try {
              $Q-&gt;execute();
          } catch (PDOException $e) {
              $rollback = true;
          }
      }
  
      if ($rollback) {
          echo 'rollbacking...';
          DBCon::getCon()-&gt;rollBack();
      } else {
          echo 'commiting...';
          DBCon::getCon()-&gt;commit();
      }
  
  ?&gt;
  </code></pre>
  
  <p>Why isn't the entire transaction rolled back?</p>
  
  <p>Thanks in advance.</p>