File: ApachePg.pl

package info (click to toggle)
libpg-perl 1%3A2.1.1-7
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 228 kB
  • sloc: perl: 514; ansic: 112; makefile: 7; sh: 7
file content (58 lines) | stat: -rw-r--r-- 1,776 bytes parent folder | download | duplicates (7)
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
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/perl

# $Id: ApachePg.pl,v 1.3 2004/04/20 03:25:07 bmomjian Exp $

# don't forget to create in postgres the user who is running 
# the httpd, eg 'createuser nobody' !
# 
# demo script, tested with:
#  - postgresql-7.0
#  - apache_1.3.12
#  - mod_perl-1.22
#  - perl5.6.0

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>",
       "<P><CENTER><TABLE CELLPADDING=4 CELLSPACING=2 BORDER=1>",
       "<TR><TD>Enter conninfo string: </TD>",
           "<TD>", $query->textfield(-name=>'conninfo', -size=>40, -default=>'dbname=template1'), "</TD>",
       "</TR>",
       "<TR><TD>Enter select command: </TD>",
           "<TD>", $query->textfield(-name=>'cmd', -size=>40), "</TD>",
       "</TR>",
       "</TABLE></CENTER><P>",
       "<CENTER>", $query->submit(-value=>'Submit'), "</CENTER>",
       $query->endform;

if ($query->param) {

    my $conninfo = $query->param('conninfo');
    my $conn = Pg::connectdb($conninfo);
    if (PGRES_CONNECTION_OK == $conn->status) {
        my $cmd = $query->param('cmd');
        my $result = $conn->exec($cmd);
        if (PGRES_TUPLES_OK == $result->resultStatus) {
            print "<P><CENTER><TABLE CELLPADDING=4 CELLSPACING=2 BORDER=1>\n";
            my @row;
            while (@row = $result->fetchrow) {
                print "<TR><TD>", join("</TD><TD>", @row), "</TD></TR>";
            }
            print "</TABLE></CENTER><P>\n";
        } else {
            print "<CENTER><H2>", $conn->errorMessage, "</H2></CENTER>\n";
        }
    } else {
        print "<CENTER><H2>", $conn->errorMessage, "</H2></CENTER>\n";
    }
}

print $query->end_html;