title: try....catch in mysql for transaction?
body: <p>How can I start a transaction when there is any error in the SQL statements the system will rollback the changes automatically?</p>
  
  <p><a href="https://stackoverflow.com/questions/1282283/transaction-mysql">Transaction MySQL</a></p>
  
  <p><a href="https://stackoverflow.com/questions/2708237/php-mysql-transactions-examples">PHP + MySQL transactions examples</a></p>
  
  <p>in PHP </p>
  
  <pre class="lang-php prettyprint-override"><code>try {
      // First of all, let's begin a transaction
      $db-&gt;beginTransaction();
  
      // A set of queries; if one fails, an exception should be thrown
      $db-&gt;query('first query');
      $db-&gt;query('second query');
      $db-&gt;query('third query');
  
      // If we arrive here, it means that no exception was thrown
      // i.e. no query has failed, and we can commit the transaction
      $db-&gt;commit();
  } catch (Exception $e) {
      // An exception has been thrown
      // We must rollback the transaction
      $db-&gt;rollback();
  }
  </code></pre>
  
  <p>How to repeat the logic without PHP,only MYSQL</p>