title: PHP PDO MySQL Transaction code structure
body: <p>I am trying to set up my first transaction in MySQL using PHP/PDO...</p>
  
  <p>I just have a quick question, what is the best way to determine if the previous query was successful or not?  Here is what I have right now, but I would rather find a way to test the query with an if statement.</p>
  
  <p>This is pretty much mock up code to try to get a working model.. I know $results isn't effectively testing if anything was good or bad.. i have it there more as a place holder for the real deal when the time comes..</p>
  
  <pre><code>if ($_POST['groupID'] &amp;&amp; is_numeric($_POST['groupID'])) {
      $sql = "SET AUTOCOMMIT=0";
      $dbs = $dbo-&gt;prepare($sql);
      $dbs-&gt;execute();
  
      $sql = "START TRANSACTION";
      $dbs = $dbo-&gt;prepare($sql);
      $dbs-&gt;execute();
  
      $sql = "DELETE FROM users_priveleges WHERE GroupID=:groupID";
      $dbs = $dbo-&gt;prepare($sql);
      $dbs-&gt;bindParam(":groupID", $_POST['groupID'], PDO::PARAM_INT);
      $dbs-&gt;execute();
  
      try {
          $sql = "DELETE FROM groups WHERE GroupID=:groupID LIMIT 1";
          $dbs = $dbo-&gt;prepare($sql);
          $dbs-&gt;bindParam(":groupID", $_POST['groupID'], PDO::PARAM_INT);
          $dbs-&gt;execute();
  
          $results["error"] = null;
          $results["success"] = true;
  
          try {
              $sql = "DELETE FROM users WHERE Group=:groupID";
              $dbs = $dbo-&gt;prepare($sql);
              $dbs-&gt;bindParam(":groupID", $_POST['groupID'], PDO::PARAM_INT);
              $dbs-&gt;execute();
  
              $results["error"] = null;
              $results["success"] = true;
  
              $sql = "COMMIT";
              $dbs = $dbo-&gt;prepare($sql);
              $dbs-&gt;execute();
          }
          catch (PDOException $e) {
              $sql = "ROLLBACK";
              $dbs = $dbo-&gt;prepare($sql);
              $dbs-&gt;execute();
  
              $results["error"] = "Could not delete associated users! $e";
              $results["success"] = false;
          }   
      }
      catch (PDOException $e)
      {
          $sql = "ROLLBACK";
          $dbs = $dbo-&gt;prepare($sql);
          $dbs-&gt;execute();
  
          $results["error"] = "COULD NOT REMOVE GROUP! $e";
          $results["success"] = false;
      }
  }
  </code></pre>