Esempio n. 1
0
$newconn = function () use($instance) {
    return new DB($instance());
};
$table = 'test_' . time() . '_' . mt_rand(10000, 99999);
$dbmain = $newconn();
$dbmain->execute("create table {$table} (id int unsigned not null primary key) engine=innodb");
$conn1 = $newconn();
$conn2 = $newconn();
T::ok($conn1 !== $conn2, 'created two db objects');
$rs = $conn1->execute('SELECT CONNECTION_ID() as id');
$row = $rs->fetch();
$id1 = $row['id'];
$rs = $conn2->execute('SELECT CONNECTION_ID() as id');
$row = $rs->fetch();
$id2 = $row['id'];
T::isnt($id1, $id2, 'got back connection ids from each and they arent the same');
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 (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($rs = $conn1->commit(), 'committed inserted row on conn1');
//if( ! $rs ) T::debug( $conn1 );
T::ok($rs = $conn2->rollback(), 'rolled back row on conn2');
//if( ! $rs ) T::debug( $conn2 );
T::ok($rs = $dbmain->execute("select id from {$table}"), 'selected all rows from the table');
$ct = $rs->affected();
T::is($ct, 0, 'no rows in the table');