#!/usr/bin/perl
use Pg;
print "Content-type: text/html\n\n";
print "\n\n";
$con = Pg::connectdb("user=username password=yourpassword dbname=databasename");
if ($con->status != PGRES_CONNECTION_OK) {
print "connect failed";
# exit;
}
$res = $con->exec("insert into tbl1 (tim,memo) values('now','by perl')");
if($res->resultStatus != PGRES_COMMAND_OK) {
print "command failed";
# exit;
}
$res = $con->exec("select id,tim,memo from tbl1 order by id");
if($res->resultStatus != PGRES_TUPLES_OK) {
print "select failed";
# exit;
}
$N = $res->ntuples;
for ($i=0;$i<$N;$i++) {
print $res->getvalue($i,0);
print " ";
print $res->getvalue($i,1);
print " ";
print $res->getvalue($i,2);
print "
\n";
}
print "\n\n";