adding test scripts
[csql.git] / test / phptests / index2.php
blobe5138e78a961579d2636f3ed2976128b59218456
1 <html>
2 <body>
3 /* Creating table with 2 fields(int,char)
4 Insert some duplicate value in f1 field
5 Create unique index on f1 field. It should be failed saying Unique key Violation.
6 check basic INSERT, SELECT */
7 <?php
8 $conn=odbc_connect('mycsql','root','manager');
9 if (!$conn)
11 echo "Connection Failed";
12 exit(1);
15 $sth = odbc_prepare($conn,"create table t1 (f1 int, f2 char(20));");
16 $res = odbc_execute($sth);
17 if (!$res)
19 echo "Error in Creation";
20 exit(2);
22 echo "Table Created";
24 $sth = odbc_prepare($conn, "insert into t1 values (10, 'TEN');");
25 $res = odbc_execute($sth);
26 if (!$res)
28 echo "Error in Insertion";
29 exit(3);
31 echo "\nRecord Inserted";
33 $sth = odbc_prepare($conn, "insert into t1 values (10, 'ten');");
34 $res = odbc_execute($sth);
35 if (!$res)
37 echo "Error in Insertion";
38 exit(4);
40 echo "\nRecord Inserted\n";
42 $sth = odbc_prepare($conn, "create index idx1 on t1(f1) unique;");
43 $res = odbc_execute($sth);
44 if ($res)
46 odbc_exec($conn,"DROP TABLE t1;");
47 exit (5);
50 echo "\nUnique key can not be applied if duplicate record is available before\n";
53 $sth = 'select * from t1;';
54 $rs = odbc_exec($conn, $sth);
55 if (!$rs)
57 echo "Error in SQL-2";
58 exit(6);
60 echo "\nselect executed\n";
61 echo "<table><tr>";
62 echo "<th>F1</th>";
63 echo "<th>F2</th></tr>";
64 echo "\nfetch started\n";
65 while (odbc_fetch_row($rs))
67 $roll=preg_replace('/[\x00-\x09\x0B-\x19\x7F]/', '',odbc_result($rs, 1));
68 $name=preg_replace('/[\x00-\x09\x0B-\x19\x7F]/', '',odbc_result($rs, 2));
69 echo "<tr><td>$roll</td>";
70 echo "<td>$name</td></tr>\n";
72 echo "</table>";
74 $sth=odbc_prepare($conn,"DROP TABLE t1;");
75 $res = odbc_execute($sth);
76 if (!$res)
78 echo "\nError in Drop Table";
79 exit(7);
81 echo "\nTable Dropped\nTest Passed";
82 odbc_close($conn);
85 </body>
86 </html>