title: Is it possible to do an sql transaction across multiple function into one?
body: <p>I am using a few functions inside another function that updates certain things, deletes some and inserts, now my problem, if 2 above are successful or 1 and the rest aren't it could cause catastrophic outcomes. So is it possible to use 1 transaction for all 3 functions... for example:</p>
  
  <pre><code>public static function do_stuff()
  {
      //run sql in function
      SELF::function_sql_one_insert();
  
      SELF::function_sql_two_update();
  
      SELF::function_sql_three_delete();
  }
  </code></pre>
  
  <p>Like so:</p>
  
  <pre><code>public static function test()
  {
      SELF::function_sql_one_insert();
  
      SELF::function_sql_two_update();
  
      SELF::function_sql_three_delete();
  }
  
  public static function function_sql_one_insert()
  {
      //sql to run
      $sql = "INSERT INTO table
              (
                  fake_row_one,
                  fake_row_two
              )
              VALUES
              (
                  ?,
                  ?
              )";
  
      //run sql
      $fake_insert = $database-&gt;prepare($sql);
      $fake_insert-&gt;execute("yeah", "okay");
  }
  
  public static function function_sql_two_update()
  {
      //sql to run
      $sql = "UPDATE table
              SET fake_row_one = ?
              WHERE fake_row_two = ?";
  
      //run sql
      $fake_update = $database-&gt;prepare($sql);
      $fake_update-&gt;execute("blahblah", "okay");
  }
  
  public static function function_sql_three_delete()
  {
      //sql to run
      $sql = "DELETE FROM TABLE
              WHERE fake_row_two = ?";
  
      //run sql
      $fake_delete = $database-&gt;prepare($sql);
      $fake_delete-&gt;execute("okay");
  }
  </code></pre>
  
  <p>What I am trying to acomplish is if one fails revert all of them back. Is this possible? If not what can I do instead, if so, is there any cons to this?</p>