Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
summaryrefslogtreecommitdiff
blob: 670fbbecb62f1cf2985974301686768237f6de4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/local/bin/perl

# demo script, has been tested with:
#  - Postgres-6.1
#  - apache_1.2
#  - mod_perl-1.0
#  - perl5.004

use CGI;
use Pg;
use strict;

my $query = new CGI;

print  $query->header,
       $query->start_html(-title=>'A Simple Example'),
       $query->startform,
       "<CENTER><H3>Testing Module Pg</H3></CENTER>",
       "Enter the database name: ",
       $query->textfield(-name=>'dbname'),
       "<P>",
       "Enter the select command: ",
       $query->textfield(-name=>'cmd', -size=>40),
       "<P>",
       $query->submit(-value=>'Submit'),
       $query->endform;

if ($query->param) {

    my $dbname = $query->param('dbname');
    my $conn = Pg::connectdb("dbname = $dbname");
    my $cmd = $query->param('cmd');
    my $result = $conn->exec($cmd);
    my $i, $j;
    print "<P><CENTER><TABLE CELLPADDING=4 CELLSPACING=2 BORDER=1>\n";
    for ($i=0; $i < $result->ntuples; $i++) {
        print "<TR>\n";
        for ($j=0; $j < $result->nfields; $j++) {
            print "<TD ALIGN=CENTER>", $result->getvalue($i, $j), "\n";
        }
    }

    print "</TABLE></CENTER><P>\n";
}

print $query->end_html;