I connected postgreSQL database with perl using code given below
But this code is working only from command prompt & when I am logged in to postgreSQL.
But I want to view the o/p in Netscape. I am using Apache 2.0.40 & Redhat9 OS. Pls make the required modification in code. or if I have to do some enviornment setting tell me.
I am typeing http: //localhost /cgi-bin/beers.pl in Netscape.
Code is as follows.

# beers.pl - my first perl data base script!
use DBI;
$dbh = DBI->connect('dbi:Pg:dbname=test', 'postgres', 'post');
$sth = $dbh->prepare("SELECT * from statename");
$rv = $sth->execute;
while (my @row_ary = $sth->fetchrow_array)
{print " $row_ary[0] $row_ary[1]\n";}
undef $sth;
undef $dbh;


I also tried following code but it is giving me following error

DBI connect('test:localhost','postgres',...) failed: missing "=" after "test:localhost" in connection info string at DB1.pl line 21

at DB1.pl line 21. at /usr/lib/perl5/5.8.0/CGI/Carp.pm line 301.
Content-Type: text/html; charset=ISO-8859-1

Code is as follows
#! /usr/bin/perl

use strict; # to avoid misspellings, declare all variables with 'my'
use warnings;
use CGI;
use CGI::Carp qw(fatalsToBrowser); # to get the error messages on to the browser
use DBI; # to work with the database

my $cgi = CGI->new(); # create an new instance of CGI
print $cgi->header(-type => 'text/html'); # a header is required

my $statement = 'SELECT * FROM statename;';

print $cgi->h1('My first Webpage with Perl and MySQL'); # print a header
print "<b>subtitle</b>"; # print a bold subtitle

my $user = 'postgres';
my $password = 'post';
my $database = 'test';
my $host = 'localhost';
my $dbh = DBI->connect("DBI:Pg:$database:$host",$user,$passwor d) or die $!;
my $sth = $dbh->prepare($statement);
while(my @cols = $sth->fetchrow_array()){
print "@cols"; # display it in the browser

# next query
# next print