title: PHP PDO Will transaction rollback when execute fails?
body: <p>Example code:</p>
  
  <pre><code>$pdo-&gt;beginTransaction();
  
  try {   
      $query1 = $pdo-&gt;prepare(...);
      $query2 = $pdo-&gt;prepare(...);
  
      $query1-&gt;execute();
      $query2-&gt;execute();
  
      $pdo-&gt;commit();
  } catch(Exception $e){
      try {
          $pdo-&gt;rollBack();
      } catch(Exception $re){
          //...
      }
  
      //...
  }
  </code></pre>
  
  <p>I know that prepare can throw exception, and commit will throw exception if there is no transaction running.</p>
  
  <p>But is it possible to occur such situation in which prepare will success but execute fails? It would not cause rollback? Does commit also throws when execution failed (I don't think so, as documentation says it throws only when there is no transaction).</p>
  
  <p>So should I explicitly check for execution result and throw my own exceptions to cause rollback like this?:</p>
  
  <pre><code>$pdo-&gt;beginTransaction();
  
  try {
  
      $query1 = $pdo-&gt;prepare(...);
      $query2 = $pdo-&gt;prepare(...);
  
      if(!$query1-&gt;execute()){
          throw new Exception('Query1 failed to execute.');
      }
  
      if(!$query2-&gt;execute()){
          throw new Exception('Query2 failed to execute.');
      }
  
      $pdo-&gt;commit();
  } catch(Exception $e){
      try {
          $pdo-&gt;rollBack();
      } catch(Exception $re){
          //...
      }
  
      //...
  }
  </code></pre>