3 /*Testing Autocommit, Commit and rollback */
5 $conn=odbc_connect('mycsql','root','manager');
8 echo "Connection Failed";
12 $sth = odbc_prepare($conn,"CREATE TABLE t1(f1 INT, f2 CHAR(20),f3 SMALLINT,f4 BIGINT);");
13 $res = odbc_execute($sth);
16 echo "Error in Creation";
19 echo "Table Created\n";
21 $ss = odbc_autocommit($conn,FALSE);
24 $sth=odbc_prepare($conn,"DROP TABLE t1;");
25 $res = odbc_execute($sth);
29 $query1 = "INSERT INTO t1(f1,f3,f4) values(10,'ABCD',100001);";
30 $query2 = "INSERT INTO t1(f1,f2,f3) values(20,'BCAD',1);";
33 //if odbc_exec fails it will increment the $ErrorCount
34 $result1 = odbc_exec($conn,$query1) or $ErrorCount++
;
37 $sth=odbc_prepare($conn,"DROP TABLE t1;");
38 $res = odbc_execute($sth);
42 $result2 = odbc_exec($conn,$query2) or $ErrorCount++
;
45 $sth=odbc_prepare($conn,"DROP TABLE t1;");
46 $res = odbc_execute($sth);
50 $sth = 'SELECT * FROM t1;';
51 $rs = odbc_exec($conn, $sth);
54 $sth=odbc_prepare($conn,"DROP TABLE t1;");
55 $res = odbc_execute($sth);
58 odbc_result_all($rs, 'border = 2');
60 //checking for errors, commit if none, rollback else
63 $res = odbc_commit($conn);
66 $sth=odbc_prepare($conn,"DROP TABLE t1;");
67 $res = odbc_execute($sth);
70 echo "Transaction successful\n";
74 $res = odbc_rollback($conn);
77 $sth=odbc_prepare($conn,"DROP TABLE t1;");
78 $res = odbc_execute($sth);
81 echo "there were errors processing the transaction.\nNo changes were made to the database\n";
84 $sth = 'SELECT * FROM t1;';
85 $rs = odbc_exec($conn, $sth);
88 $sth=odbc_prepare($conn,"DROP TABLE t1;");
89 $res = odbc_execute($sth);
93 $rs = odbc_result_all($rs, 'border = 2');
96 $sth=odbc_prepare($conn,"DROP TABLE t1;");
97 $res = odbc_execute($sth);
101 $sth=odbc_prepare($conn,"DROP TABLE t1;");
102 $res = odbc_execute($sth);
105 echo "\nError in Drop Table";
108 echo "\nTable Dropped \nTest Passed";