Programming for SQL: Perl CGI
Perl CGI with PostgreSQL connection is easly to do. First of all you need to know how to program in Perl. I will not be talking about that here but if you visit www.Perl.org you can find a lot of information.
Things you need to do before using these examples.| <!--#include virtual="/cgi-bin/Hello.cgi" --> |
| use Pg; |
|
$DBConnection = Pg::connectdb("user=librarian dbname=library"); if($DBConnection->status eq PGRES_CONNECTION_OK) { print "We are connected!"; } else { print "Error connecting to database!"; } |
|
$SQL_Command = "SELECT * FROM $TableName"; $Result = $DBConnection->exec($SQL_Command); |
|
$NumberOfRecords = $Result->ntuples(); $NumberOfFields = $Result->nfields(); |
| $SomeText = $Result->getvalue($ALoopCounter,$BLoopCounter); |
|
$SQL_Command = "INSERT INTO mytable VALUES ('PostgreSQL', 'is', 'easy')"; $Result = $DBConnection->exec($SQL_Command); if($Result->resultStatus ne PGRES_COMMAND_OK) { print "Error connecting to database!"; } else { print "We are connected!"; } |