Exemple #1
0
 /**
  * Start a SQL transaction
  *
  * Some examples of different ways to use transactions:
  * 
  * 
  * 
  * // 1) Example using the xdatabase Query class
  * try
  * {
  *   Query::begin();
  *   Query::sql($sql)->execute();
  *   // ... more code/queries
  *   Query::commit();
  * }
  * catch (Exception $e)
  * {
  *   Query::rollback();
  * }
  * 
  * // 2) Example using existing Kohana style
  * try
  * {
  * 	 $db = Database::instance();
  *   $db->begin();
  *   DB::query(Database::INSERT, $sql)->execute($db);
  *   // ... more code/queries
  *   $db->commit();
  * }
  * catch (Exception $e)
  * {
  *   $db->rollback();
  * }
  * 
  * // 3) Example using the Query class without the default database
  * $db = Database::instance('alternate');
  * Query::begin($db);
  * Query::sql($sql)->execute($db);
  * // ... more code/queries
  * // If some conditions met:
  * Query::commit($db);
  * // Else
  * Query::rollback($db);
  * 
  * @return boolean
  */
 public static function begin($db = NULL)
 {
     $query = new Database_Query(NULL, NULL);
     return $query->begin($db);
 }