title: How can I implement commit/rollback for MySQL in PHP?
body: <p>Well basically I have this script that takes a long time to execute and occasionally times out and leaves semi-complete data floating around my database. (Yes I know in a perfect world I would fix THAT instead of implementing commits and rollbacks but I am forced to not do that)</p>
  
  <p>Here is my basic code (dumbed down for simplicity):</p>
  
  <pre><code>$database = new PDO("mysql:host=host;dbname=mysql_db","username","password");
  
  while (notDone())
  {
      $add_row = $database-&gt;prepare("INSERT INTO table (columns) VALUES (?)");
      $add_row-&gt;execute(array('values'));
  
      //PROCESSING STUFF THAT TAKES A LONG TIME GOES HERE
  }
  
  $database = null;
  </code></pre>
  
  <p>So my problem is that if that if the entire process within that while loop isn't complete then I don't want the row inserted to remain there.  I think that somehow I could use commits/rollbacks at the beginning and end of the while loop to do this but don't know how.</p>