~ubuntu-branches/ubuntu/hardy/php5/hardy-updates

« back to all changes in this revision

Viewing changes to tests/odbc-t3.php

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-10-09 03:14:32 UTC
  • Revision ID: james.westby@ubuntu.com-20051009031432-kspik3lobxstafv9
Tags: upstream-5.0.5
ImportĀ upstreamĀ versionĀ 5.0.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<HTML>
 
2
<HEAD>
 
3
<TITLE>Database test #3</TITLE>
 
4
</HEAD>
 
5
<BODY>
 
6
<H1>ODBC Test 3 - Insert records</H1>
 
7
<?php
 
8
  if(isset($dbuser)){
 
9
        echo "Connecting to $dsn as $dbuser\n";
 
10
        $conn = odbc_connect($dsn,$dbuser,$dbpwd);
 
11
        if(!$conn){
 
12
?>
 
13
<H2>Error connecting to database! Check DSN, username and password</H2>
 
14
<?php
 
15
        }else{
 
16
?>
 
17
 - OK<p>
 
18
Clearing table "php_test"
 
19
<?php
 
20
                error_reporting(0);
 
21
                $res=odbc_exec($conn,"delete from php_test");
 
22
                odbc_free_result($res);
 
23
                error_reporting(1);
 
24
?>
 
25
 - OK<p>
 
26
Inserting into table "php_test"
 
27
<?php
 
28
                $sqlfloat = '00.0';
 
29
                $sqlint = 1000;
 
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);
 
37
                }
 
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);
 
42
?>
 
43
 - OK<p>
 
44
<H3>The table "php_test" should now contain the following values:</H3>
 
45
<table>
 
46
 <tr>
 
47
  <th>A</th><th>B</th><th>C</th><th>D</th>
 
48
 </tr>
 
49
 <tr>
 
50
  <td>test-1</td><td>1001</td><td>100.01</td><td>php - values 1</td>
 
51
 </tr>
 
52
 <tr>
 
53
  <td>test-2</td><td>1002</td><td>200.02</td><td>php - values 2</td>
 
54
 </tr>
 
55
 <tr>
 
56
  <td>test-3</td><td>1003</td><td>300.03</td><td>php - values 3</td>
 
57
 </tr>
 
58
 <tr>
 
59
  <td>test-4</td><td>1004</td><td>400.04</td><td>php - values 4</td>
 
60
 </tr>
 
61
 <tr>
 
62
  <td>test-5</td><td>1005</td><td>500.05</td><td>php - values 5</td>
 
63
 </tr>
 
64
</table>
 
65
 
 
66
<H3>Actual contents of table "php_test":</H3>
 
67
<?php
 
68
                        $res = odbc_exec($conn, "select * from php_test");
 
69
                        odbc_result_all($res);
 
70
                }
 
71
?>
 
72
<p>
 
73
 <HR width="50%">
 
74
<p>
 
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>
 
77
<?php
 
78
        }
 
79
  } else {
 
80
?>
 
81
<form action=odbc-t3.php method=post>
 
82
<table border=0>
 
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>
 
86
</table>
 
87
<input type=submit value=connect>
 
88
 
 
89
</form>
 
90
<?php
 
91
  } 
 
92
?>
 
93
</BODY>
 
94
</HTML>
 
95