adding test scripts
[csql.git] / test / phptests / autocommit_rollback_commit.php
blobfec313b2ced0f7ed6b5a224e685cbf871c4f736b
1 <html>
2 <body>
3 /*Testing Autocommit, Commit and rollback */
4 <?php
5 $conn=odbc_connect('mycsql','root','manager');
6 if (!$conn)
8 echo "Connection Failed";
9 exit(1);
12 $sth = odbc_prepare($conn,"CREATE TABLE t1(f1 INT, f2 CHAR(20),f3 SMALLINT,f4 BIGINT);");
13 $res = odbc_execute($sth);
14 if (!$res)
16 echo "Error in Creation";
17 exit(2);
19 echo "Table Created\n";
21 $ss = odbc_autocommit($conn,FALSE);
22 if (!$ss)
24 $sth=odbc_prepare($conn,"DROP TABLE t1;");
25 $res = odbc_execute($sth);
26 exit(3);
29 $query1 = "INSERT INTO t1(f1,f3,f4) values(10,'ABCD',100001);";
30 $query2 = "INSERT INTO t1(f1,f2,f3) values(20,'BCAD',1);";
32 $ErrorCount = 0;
33 //if odbc_exec fails it will increment the $ErrorCount
34 $result1 = odbc_exec($conn,$query1) or $ErrorCount++;
35 if (!$result1)
37 $sth=odbc_prepare($conn,"DROP TABLE t1;");
38 $res = odbc_execute($sth);
39 exit(4);
42 $result2 = odbc_exec($conn,$query2) or $ErrorCount++;
43 if (!$result2)
45 $sth=odbc_prepare($conn,"DROP TABLE t1;");
46 $res = odbc_execute($sth);
47 exit(5);
50 $sth = 'SELECT * FROM t1;';
51 $rs = odbc_exec($conn, $sth);
52 if (!$rs)
54 $sth=odbc_prepare($conn,"DROP TABLE t1;");
55 $res = odbc_execute($sth);
56 exit(6);
58 odbc_result_all($rs, 'border = 2');
60 //checking for errors, commit if none, rollback else
61 if($ErrorCount == 0)
63 $res = odbc_commit($conn);
64 if (!$res)
66 $sth=odbc_prepare($conn,"DROP TABLE t1;");
67 $res = odbc_execute($sth);
68 exit(7);
70 echo "Transaction successful\n";
72 else
74 $res = odbc_rollback($conn);
75 if (!$res)
77 $sth=odbc_prepare($conn,"DROP TABLE t1;");
78 $res = odbc_execute($sth);
79 exit(8);
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);
86 if (!$rs)
88 $sth=odbc_prepare($conn,"DROP TABLE t1;");
89 $res = odbc_execute($sth);
90 exit(9);
93 $rs = odbc_result_all($rs, 'border = 2');
94 if (!$rs)
96 $sth=odbc_prepare($conn,"DROP TABLE t1;");
97 $res = odbc_execute($sth);
98 exit(10);
101 $sth=odbc_prepare($conn,"DROP TABLE t1;");
102 $res = odbc_execute($sth);
103 if (!$res)
105 echo "\nError in Drop Table";
106 exit(11);
108 echo "\nTable Dropped \nTest Passed";
109 odbc_close($conn);
112 </body>
113 </html>