Last active
August 29, 2015 14:14
-
-
Save phpdave/bd8507b0f8aa6aeb57b6 to your computer and use it in GitHub Desktop.
Code to test out isolation level. While this program is running execute a SQL SELECT statement on the same table and see if you get less than 10,000 records at any point
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
error_reporting(E_ALL & ~E_NOTICE); | |
ini_set('display_errors', TRUE); | |
ini_set('display_startup_errors', TRUE); | |
for ($index = 0; $index < 10000; $index++) | |
{ | |
$insertdata[] = array('test'); | |
} | |
$options = array('i5_commit' => DB2_I5_TXN_SERIALIZABLE,'autocommit' => DB2_AUTOCOMMIT_OFF); | |
$db2Connection = db2_connect('', '', '', $options); | |
if (!$db2Connection) | |
{ | |
echo "false - Connection failed.";exit(); | |
} | |
$sql = "DELETE FROM MYLIB.MYTABLE"; | |
$stmt = db2_exec($db2Connection, $sql); | |
$sql = "INSERT INTO MYLIB.MYTABLE (MYCOL1) VALUES(?)"; | |
$insertstmt = db2_prepare($db2Connection, $sql); | |
foreach($insertdata as $row) | |
{ | |
try | |
{ | |
$result = db2_execute($insertstmt, $row); | |
} | |
catch (Exception $exc) | |
{ | |
$result=false; | |
} | |
if($result==false) | |
{ | |
echo db2_stmt_errormsg(); | |
echo "Dump of Array being inserted:<br>"; var_dump($row); | |
} | |
} | |
//THIS WORKS - Commitment Control works, Isolation Levels do not (stopping others from reading the data as your modifying the table) | |
$commitResult = db2_rollback($db2Connection); | |
var_dump($commitResult); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment