Beispiel #1
0
T::ok($conn2->start(), 'started a transaction on conn2');
$rs = $conn1->execute("insert into {$table} values (1)");
T::ok($rs, 'inserted a row into test table from conn1');
//if( ! $rs ) T::debug( $conn1 );
$rs = $conn2->execute("insert into {$table} values(2)");
T::ok($rs, 'inserted a row into test table from conn2');
//if( ! $rs ) T::debug( $conn2 );
T::ok($conn1->commit(), 'committed inserted row on conn1');
T::ok($conn2->commit(), 'committed inserted row on conn2');
T::ok($rs = $dbmain->execute("select id from {$table}"), 'selected all rows from the table');
$ct = $rs->affected();
T::is($ct, 2, '2 rows in the table');
//var_dump( $rs );
//var_dump( $conn1 );
Transaction::reset();
T::ok(Transaction::start(), 'started a transaction at the global level');
$conn1 = $newconn();
$conn2 = $newconn();
T::ok($conn1->start(), 'started a transaction on conn1');
T::ok($conn2->start(), 'started a transaction on conn2');
$rs = $conn1->execute("insert into {$table} values (3)");
T::ok($rs, 'inserted a row into test table from conn1');
//if( ! $rs ) T::debug( $conn1 );
$rs = $conn2->execute("insert into {$table} values(4)");
T::ok($rs, 'inserted a row into test table from conn2');
//if( ! $rs ) T::debug( $conn2 );
T::ok($conn1->commit(), 'committed inserted row on conn1');
T::ok($conn2->commit(), 'committed inserted row on conn2');
T::ok(Transaction::rollback(), 'rolled back the transaction at the global level');
T::ok($rs = $dbmain->execute("select id from {$table}"), 'selected all rows from the table');
$ct = $rs->affected();
Beispiel #2
0
Datei: DB.php Projekt: wukka/db
 /**
  * start a new transaction.
  * connected to the Transaction singleton to support multi-database transactions.
  */
 public function start()
 {
     $args = func_get_args();
     $auth = isset($args[0]) ? $args[0] : NULL;
     if ($this->core instanceof Iface) {
         return $this->core->start($auth);
     }
     if ($auth == Transaction::SIGNATURE) {
         if ($this->lock) {
             return FALSE;
         }
         $this->txn = TRUE;
         $f = $this->_[__FUNCTION__];
         return (bool) $f($auth);
     }
     Transaction::start();
     if (!Transaction::add($this)) {
         return FALSE;
     }
     return TRUE;
 }