#!c:/perl/bin/perl
#
#
# a simple test script for connecting to the default
# PostgreSQL database.
#
# Copyright 2000 DVL Software Limited
#
# see http://freebsddiary.org/postgresql-perl.html
#

use DBI;
use strict;

my $dbh;
my $sth;
my @vetor;
my $field;

$dbh = DBI->connect('DBI:Pg:dbname=YourDBName', 'UserID', '');
if ($dbh) {
   print "connected\n";

   $sth = $dbh->prepare("SELECT * from table limit 20");
   $sth->execute;

   print "<table>\n";
   while (@vetor = $sth->fetchrow) {
      print "<TR>\n";
      foreach $field (@vetor) {
         print "<TD VALIGN=TOP>$field</TD>\n";
      }
      print "</TR>\n";
   }

   print "</table>\n";

   $sth->finish;
   $dbh->disconnect();
} else {
   print "Cannot connect to Postgres server: $DBI::errstr\n";
   print " db connection failed\n";
}