I have the following code to test rollback transaction processing. I get a
count of records from a table, then delete all the records, then perform a
roll back which should (supposedly) restore the records back to the table.
I am able to confirm that the db2_autocommit_off is indeed getting set, but
the rollback function never rolls back the prior deletion. I can't seem to
find much on the internet. What am I missing? (fyi, $telusr and $telpwd
are being set correctly but I have not included the code here).



For example, if I start out with 2 records, here is the result I get:

Original record count: 2

AUTOCOMMIT is off.

Record count after delete: 0

Record count after rollback: 0



$db = "*LOCAL";

$options = array ('i5_naming' => DB2_I5_NAMING_ON, 'autocommit' =>
DB2_AUTOCOMMIT_OFF );

if ($conn) {

$stmt = db2_exec($conn, "SELECT count(*) FROM teltrn");

$res = db2_fetch_array( $stmt );

echo "Original record count: " . $res[0] . "\n";



// Turn AUTOCOMMIT off

//db2_autocommit($conn, DB2_AUTOCOMMIT_OFF);

$ac = db2_autocommit($conn);

if ($ac == 0) {

print "AUTOCOMMIT is off.";

} else {

print "AUTOCOMMIT is on.";

}

// Delete all rows from teltrn

db2_exec($conn, "DELETE FROM teltrn");



$stmt = db2_exec($conn, "SELECT count(*) FROM teltrn");

$res = db2_fetch_array( $stmt );

echo "Record count after delete: " . $res[0] . "\n";



// Roll back the DELETE statement

db2_rollback( $conn );



$stmt = db2_exec( $conn, "SELECT count(*) FROM teltrn" );

$res = db2_fetch_array( $stmt );

echo "Record count after rollback: " . $res[0] . "\n";

}


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.