Subject transaction problem
Author leonbadman
hi, this is my code (T is a table (id integer)):


$connection = ibase_connect('/my/database/database.gdb', '*', '*');

$transaction = ibase_trans(IBASE_DEFAULT, $connection);
$transaction1 = ibase_trans(IBASE_DEFAULT, $connection);


$pstm = ibase_prepare($connection, "SELECT COUNT(*) AS N FROM T");
$rs = ibase_execute($pstm);
$r = ibase_fetch_object($rs);
echo "BEFORE:" . $r->N . "<br>";
ibase_free_query($pstm);


// STEP 0
$pstm = ibase_prepare($connection, "INSERT INTO T VALUES (1)");
ibase_execute($pstm);
ibase_free_query($pstm);

// STEP 1
$pstm = ibase_prepare($transaction, "INSERT INTO T VALUES (1)");
ibase_execute($pstm);
ibase_free_query($pstm);

// STEP 2
$pstm = ibase_prepare($transaction1, "INSERT INTO T VALUES (1)");
ibase_execute($pstm);
ibase_free_query($pstm);

// STEP 3
$pstm = ibase_prepare($transaction1, "INSERT INTO T VALUES (1)");
ibase_execute($pstm);
ibase_free_query($pstm);

// STEP 4
$pstm = ibase_prepare($transaction1, "INSERT INTO T VALUES (1)");
ibase_execute($pstm);
ibase_free_query($pstm);

// STEP 5
$pstm = ibase_prepare($connection, "SELECT COUNT(*) AS N FROM T");
$rs = ibase_execute($pstm);
$r = ibase_fetch_object($rs);
echo "AFTER (CONN):" . $r->N . "<br>";
ibase_free_query($pstm);

// STEP 6
$pstm = ibase_prepare($transaction, "SELECT COUNT(*) AS N FROM T");
$rs = ibase_execute($pstm);
$r = ibase_fetch_object($rs);
echo "AFTER (TRAN):" . $r->N . "<br>";
ibase_free_query($pstm);


// STEP 7
$pstm = ibase_prepare($transaction1, "SELECT COUNT(*) AS N FROM T");
$rs = ibase_execute($pstm);
$r = ibase_fetch_object($rs);
echo "AFTER (TRAN1):" . $r->N . "<br>";
ibase_free_query($pstm);


ibase_commit($transaction1);
ibase_commit($transaction);


// STEP 8
$pstm = ibase_prepare($connection, "SELECT COUNT(*) AS N FROM T");
$rs = ibase_execute($pstm);
$r = ibase_fetch_object($rs);
echo "AFTER COMMIT (CONN):" . $r->N . "<br>";
ibase_free_query($pstm);


ibase_close($connection);


now start with an empty table, the output is:

BEFORE:0
AFTER (CONN):2
AFTER (TRAN):2
AFTER (TRAN1):3
AFTER COMMIT (CONN):5


so, $connection and $transaction are the same thing ($transaction1
seems to work perfect). I would have expected this result:

BEFORE:0
AFTER (CONN):1
AFTER (TRAN):1
AFTER (TRAN1):3
AFTER COMMIT (CONN):5

what is my mistake?


Thanx.
Leonardo Cosmai