title: MySQL PHP Transaction across databases
body: <p>I cannot find a definitive answer to whether or not it's allowed to make transactions in PHP span multiple databases.</p>
  
  <p>I am using the same connection object (mysqli) and performing the transaction(s) in this manner:</p>
  
  <pre><code>$mysqli-&gt;autocommit(false);
  
  try {
  
      // Assume here that some code would throw an exception
  
      $stmt = $mysqli-&gt;prepare("INSERT INTO db1.x (column) VALUES (y)");
      $stmt-&gt;execute();
      $stmt-&gt;close();
  
      $stmt = $mysqli-&gt;prepare("INSERT INTO db2.x (column) VALUES (y)");
      $stmt-&gt;execute();
      $stmt-&gt;close();
  
      $mysqli-&gt;commit();
      // Great success
  
  } catch (Exception $e) {
  
      $mysqli-&gt;rollback();
      throw $e; // handle elsewhere
  
  }
  </code></pre>
  
  <p>Is this allowed and will it properly commit and roll back? According to the manual (<a href="http://dev.mysql.com/doc/refman/5.6/en/xa.html" rel="nofollow">http://dev.mysql.com/doc/refman/5.6/en/xa.html</a>) and other threads on SO, it seems I need to use XA statements, but it's not really clear (to me) if this is when using multiple database servers, multiple connections or just in general when executing above code.</p>