windows porting build fix for linux
[csql.git] / examples / php / phpexample.php
blob852a6a3a11d385fd12a3fdd1c28efce9f1d3fef5
1 <html>
2 <body>
3 /*Create table and test all DML Operation on the table */
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));");
13 $res = odbc_execute($sth);
14 if (!$res)
16 echo "Error in Creation";
17 exit(2);
19 echo "Table Created";
21 $sth = odbc_prepare($conn, "INSERT INTO t1(f1, f2) VALUES(12,'Lakshye');");
22 $res = odbc_execute($sth);
23 if (!$res)
25 echo "Error in Insertion";
26 exit(3);
28 echo "\nRecord Inserted";
29 $sth = odbc_prepare($conn, "INSERT INTO t1(f1, f2) VALUES(13,'CSQL');");
30 $res = odbc_execute($sth);
31 if (!$res)
33 echo "Error in Insertion";
34 exit(3);
36 echo "\nRecord Inserted";
38 $sth = 'select * from t1;';
39 $rs = odbc_exec($conn, $sth);
40 if (!$rs)
42 echo "Error in selection";
43 exit(4);
45 echo "\nselect executed\n";
47 echo "<table><tr>";
48 echo "<th>ROLL</th>";
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";
58 echo "</table>";
60 $sth = odbc_prepare($conn, "UPDATE t1 SET f2='TWELVE' WHERE f1=12;");
61 $res = odbc_execute($sth);
62 if (!$res)
64 echo "\nError in Updation\n";
65 exit(5);
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";
78 echo "</table>";
80 $sth = odbc_prepare($conn, "DELETE FROM t1 WHERE f1=13;");
81 $res = odbc_execute($sth);
82 if (!$res)
84 echo "\nError in Deletion\n";
85 exit(6);
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";
98 echo "</table>";
100 $sth=odbc_prepare($conn,"DROP TABLE t1;");
101 $res = odbc_execute($sth);
102 if (!$res)
104 echo "\nError in Drop Table";
105 exit(7);
107 echo "\nTable Dropped \nTest Passed";
108 odbc_close($conn);
110 </body>
111 </html>