3
<TITLE>Database test #3</TITLE>
6
<H1>ODBC Test 3 - Insert records</H1>
9
echo "Connecting to $dsn as $dbuser\n";
10
$conn = odbc_connect($dsn,$dbuser,$dbpwd);
13
<H2>Error connecting to database! Check DSN, username and password</H2>
18
Clearing table "php_test"
21
$res=odbc_exec($conn,"delete from php_test");
22
odbc_free_result($res);
26
Inserting into table "php_test"
30
$stmt = odbc_prepare($conn, "insert into php_test values(?,?,?,?)");
31
for($i=1; $i<=5; $i++){
32
$values[0] = "test-$i";
33
$values[1] = $sqlint + $i;
34
$values[2] = $i . $sqlfloat . $i;
35
$values[3] = "php - values $i";
36
$ret = odbc_execute($stmt, &$values);
38
odbc_free_result($stmt);
39
$res = odbc_exec($conn, "select count(*) from php_test");
40
if($res && (odbc_result($res, 1) == 5)){
41
odbc_free_result($res);
44
<H3>The table "php_test" should now contain the following values:</H3>
47
<th>A</th><th>B</th><th>C</th><th>D</th>
50
<td>test-1</td><td>1001</td><td>100.01</td><td>php - values 1</td>
53
<td>test-2</td><td>1002</td><td>200.02</td><td>php - values 2</td>
56
<td>test-3</td><td>1003</td><td>300.03</td><td>php - values 3</td>
59
<td>test-4</td><td>1004</td><td>400.04</td><td>php - values 4</td>
62
<td>test-5</td><td>1005</td><td>500.05</td><td>php - values 5</td>
66
<H3>Actual contents of table "php_test":</H3>
68
$res = odbc_exec($conn, "select * from php_test");
69
odbc_result_all($res);
75
<A HREF="odbc-t4.php?dbuser=<?php echo "$dbuser&dsn=$dsn&dbpwd=$dbpwd" ?>">Proceed to next test</A>
76
| <A HREF="<?php echo $PHP_SELF ?>">Change login information</A>
81
<form action=odbc-t3.php method=post>
83
<tr><td>Database: </td><td><input type=text name=dsn></td></tr>
84
<tr><td>User: </td><td><input type=text name=dbuser></td></tr>
85
<tr><td>Password: </td><td><input type=password name=dbpwd></td></tr>
87
<input type=submit value=connect>