title: How to Rollback and Commit using MySQLi Transactions?
body: <p>I seem to be having trouble with the rollback feature in PHP7. Here's my code, but if I supply the queries and put an error into one of them, it won't roll back. It still commits everything that had been completed.</p>
  
  <pre><code>function sql_transaction(...$queries) {
      global $db;
  
      $success = 1;
      $db-&gt;autocommit(FALSE);
  
      foreach($queries as $query) {
          $result = $db-&gt;query($query);
          echo $result;
          if(!$result) {
              $success = 0;
              break;
          }
      }
  
      if($success == 1) {
          $db-&gt;commit();
      }else{
          $db-&gt;rollback();
      }
      $db-&gt;autocommit(TRUE);
      return $success;
  }
  </code></pre>