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 */
8 $conn=odbc_connect('mycsql','root','manager');
11 echo "Connection Failed";
15 $sth = odbc_prepare($conn,"create table t1 (f1 int, f2 char(20));");
16 $res = odbc_execute($sth);
19 echo "Error in Creation";
24 $sth = odbc_prepare($conn, "insert into t1 values (10, 'TEN');");
25 $res = odbc_execute($sth);
28 echo "Error in Insertion";
31 echo "\nRecord Inserted";
33 $sth = odbc_prepare($conn, "insert into t1 values (10, 'ten');");
34 $res = odbc_execute($sth);
37 echo "Error in Insertion";
40 echo "\nRecord Inserted\n";
42 $sth = odbc_prepare($conn, "create index idx1 on t1(f1) unique;");
43 $res = odbc_execute($sth);
46 odbc_exec($conn,"DROP TABLE t1;");
47 echo("Error in Unique Index\nTest Failed");
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);
57 echo "Error in SQL-2";
60 echo "\nselect executed\n";
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";
74 $sth=odbc_prepare($conn,"DROP TABLE t1;");
75 $res = odbc_execute($sth);
78 echo "\nError in Drop Table";
81 echo "\nTable Dropped\nTest Passed";