123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <?php
- /**
- * Part of the Fuel framework.
- *
- * @package Fuel
- * @version 1.5
- * @author Fuel Development Team
- * @license MIT License
- * @copyright 2010 - 2013 Fuel Development Team
- * @link http://fuelphp.com
- */
- /**
- * Interact with Database Transactions
- *
- * @author five07
- * @copyright (c) 2011 five07
- * @license https://github.com/five07/Fuel-Addons/blob/master/LICENSE
- */
- namespace Fuel\Core;
- /**
- * @deprecated remove in v1.2
- */
- class Database_Transaction
- {
- /**
- * @var Database_Transaction for Singleton-like usage
- */
- protected static $_instance = null;
- /**
- * @var \Fuel\Core\Database_Connection
- */
- protected $_db;
- public static function instance()
- {
- if (static::$_instance == null)
- {
- static::$_instance = static::forge();
- }
- return static::$_instance;
- }
- /**
- * Creates a new instance
- *
- * @param string $instance
- */
- public static function forge($instance = null)
- {
- logger(\Fuel::L_WARNING, 'The Database_Transaction class is deprecated, use the connection driver methods instead.', __METHOD__);
- return new static($instance);
- }
- /**
- * The constructor
- *
- * @param string $instance
- */
- public function __construct($instance = null)
- {
- $this->_db = Database_Connection::instance($instance);
- }
- /**
- * Start your transaction before a set of dependent queries
- */
- public function start()
- {
- $this->_db->start_transaction();
- }
- /**
- * Complete your transaction on the set of queries
- */
- public function complete()
- {
- try
- {
- static::commit();
- }
- catch (\Exception $e)
- {
- static::rollback();
- }
- }
- /**
- * If the group of queries had no errors, this returns TRUE
- * Otherwise, will return FALSE
- *
- * @return boolean
- */
- public function status()
- {
- return true;
- }
- /**
- * Commit the successful queries and reset AUTOCOMMIT
- * This is called automatically if you use Database_Transaction::complete()
- * It can also be used manually for testing
- */
- public function commit()
- {
- $this->_db->commit_transaction();
- }
- /**
- * Rollback the failed queries and reset AUTOCOMMIT
- * This is called automatically if you use Database_Transaction::complete()
- * It can also be used manually for testing
- */
- public function rollback()
- {
- $this->_db->rollback_transaction();
- }
- /**
- * Return the database errors
- *
- * @return mixed (array or false)
- */
- public function errors()
- {
- return false;
- }
- }
|