#!/usr/local/bin/perl # demo script, tested with: # - PostgreSQL-6.3 # - apache_1.3 # - mod_perl-1.08 # - perl5.004_04 use CGI; use Pg; use strict; my $query = new CGI; print $query->header, $query->start_html(-title=>'A Simple Example'), $query->startform, "

Testing Module Pg

", "

", "", "", "", "", "", "", "
Enter conninfo string: ", $query->textfield(-name=>'conninfo', -size=>40, -default=>'dbname=template1 host=localhost'), "
Enter select command: ", $query->textfield(-name=>'cmd', -size=>40), "

", "

", $query->submit(-value=>'Submit'), "
", $query->endform; if ($query->param) { my $conninfo = $query->param('conninfo'); my $conn = Pg::connectdb($conninfo); if ($conn->status == PGRES_CONNECTION_OK) { my $cmd = $query->param('cmd'); my $result = $conn->exec($cmd); print "

\n"; my @row; while (@row = $result->fetchrow) { print "\n"; } print "
", join("", @row), "

\n"; } else { print "

Connect to database failed

\n"; } } print $query->end_html;