3 /*Create table and test all DML Operation on the table */
5 $conn=odbc_connect('mycsql','root','manager');
8 echo "Connection Failed";
12 $sth = odbc_prepare($conn,"CREATE TABLE t1(f1 INT, f2 CHAR(20));");
13 $res = odbc_execute($sth);
16 echo "Error in Creation";
21 $sth = odbc_prepare($conn, "INSERT INTO t1(f1, f2) VALUES(12,'Lakshye');");
22 $res = odbc_execute($sth);
25 echo "Error in Insertion";
28 echo "\nRecord Inserted";
29 $sth = odbc_prepare($conn, "INSERT INTO t1(f1, f2) VALUES(13,'CSQL');");
30 $res = odbc_execute($sth);
33 echo "Error in Insertion";
36 echo "\nRecord Inserted";
38 $sth = 'select * from t1;';
39 $rs = odbc_exec($conn, $sth);
42 echo "Error in selection";
45 echo "\nselect executed\n";
49 echo "<th>NAME</th></tr>";
50 echo "\nfetch started\n";
51 while (odbc_fetch_row($rs))
53 $roll=preg_replace('/[\x00-\x09\x0B-\x19\x7F]/', '',odbc_result($rs, 1));
54 $name=preg_replace('/[\x00-\x09\x0B-\x19\x7F]/', '',odbc_result($rs, 2));
55 echo "<tr><td>$roll</td>";
56 echo "<td>$name</td></tr>\n";
60 $sth = odbc_prepare($conn, "UPDATE t1 SET f2='TWELVE' WHERE f1=12;");
61 $res = odbc_execute($sth);
64 echo "\nError in Updation\n";
67 echo "\nRecord Updated\n";
69 $sth = 'select * from t1;';
70 $rs = odbc_exec($conn, $sth);
71 while (odbc_fetch_row($rs))
73 $roll=preg_replace('/[\x00-\x09\x0B-\x19\x7F]/', '',odbc_result($rs, 1));
74 $name=preg_replace('/[\x00-\x09\x0B-\x19\x7F]/', '',odbc_result($rs, 2));
75 echo "<tr><td>$roll</td>";
76 echo "<td>$name</td></tr>\n";
80 $sth = odbc_prepare($conn, "DELETE FROM t1 WHERE f1=13;");
81 $res = odbc_execute($sth);
84 echo "\nError in Deletion\n";
87 echo "\nRecord Deleted\n";
89 $sth = 'select * from t1;';
90 $rs = odbc_exec($conn, $sth);
91 while (odbc_fetch_row($rs))
93 $roll=preg_replace('/[\x00-\x09\x0B-\x19\x7F]/', '',odbc_result($rs, 1));
94 $name=preg_replace('/[\x00-\x09\x0B-\x19\x7F]/', '',odbc_result($rs, 2));
95 echo "<tr><td>$roll</td>";
96 echo "<td>$name</td></tr>\n";
100 $sth=odbc_prepare($conn,"DROP TABLE t1;");
101 $res = odbc_execute($sth);
104 echo "\nError in Drop Table";
107 echo "\nTable Dropped \nTest Passed";