title: Does execute breakes the PDO Transaction?
body: <p>I am writing user input to 2 MySQL tables as follows: </p>
  
  <p>(a) insert some data to table-A, </p>
  
  <p>(b) get the lastInsertId, </p>
  
  <p>(c) insert other data to table-B. </p>
  
  <p>I have:</p>
  
  <pre><code>            $this-&gt;conn-&gt;beginTransaction();
              $stmt = $this-&gt;conn-&gt;prepare("
                      INSERT INTO requests
                          ($creation_date, etc...) // some data 
                          VALUES(:creation_date, etc..);"); // some values
  
  
              $stmt-&gt;bindparam(":creation_date",$creation_date);
              ...
  
              $stmt-&gt;execute();
  </code></pre>
  
  <p>At this point, ultimately what I need is just to get the lastInsertId, 
  but it seems it only becomes available afterthe first <code>$stmt-&gt;execute()</code> as otherwise it returns 0 due to fact that specific actions within transaction have not been physically started (please confirm if otherwise). </p>
  
  <p>Further code as follows:</p>
  
  <pre><code>            $lastInsertId = $this-&gt;conn-&gt;lastInsertId();
  
              $stmt = $this-&gt;conn-&gt;prepare("
                      INSERT INTO other_requests
                          (requests_id,...) // some more data 
                          VALUES(:requests_id,...);"); // some more values
  
              $stmt-&gt;bindparam(":requests_id", $lastInsertId);
              $stmt-&gt;bindparam(...); // some more bindings
              $stmt-&gt;execute();
              $this-&gt;conn-&gt;commit();
  </code></pre>
  
  <p><strong>Questions:</strong></p>
  
  <ol>
  <li><p>I am concerned if the first <code>$stmt-&gt;execute();</code> in the middle of transaction code somehow interrupts the transaction. My understanding is that it shouldn't - but so far haven't haven't found any good proof to that.</p></li>
  <li><p>I am in search for a more elegant solution, as currently it seems there's too much code for a simple task.</p></li>
  </ol>
  
  <p>Thanks for any advise</p>