#!/usr/bin/perl # $Id: ApachePg.pl,v 1.2 2001/09/04 11:41:04 petere Exp $ # demo script, tested with: # - PostgreSQL-6.4 # - apache_1.3.1 # - mod_perl-1.15 # - perl5.005_02 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'), "
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 (PGRES_CONNECTION_OK == $conn->status) { my $cmd = $query->param('cmd'); my $result = $conn->exec($cmd); if (PGRES_TUPLES_OK == $result->resultStatus) { print "

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

\n"; } else { print "

", $conn->errorMessage, "

\n"; } } else { print "

", $conn->errorMessage, "

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