Using Perl and ODBC with PSQL
Note:
This procedure assumes you have a working installation of PSQL v12, Perl, and an ODBC distribution. A free version of ODBC is available at
http://www.iODBC.org
. Perl can be found at
http://www.perl.org
►
To Get PSQL to work with Perl's ODBC Interface
1
Download the DBI (database interface) support for Perl.
Read the Readme or INSTALL for instructions.
2
Download the ODBC DBD database driver for Perl.
Please see the installation instructions in the Readme or INSTALL file.
3
Make sure you have the proper environment variables set, as shown in the following example. Note, this is also explained in the iODBC docs.
Code Snippet for Perl and DBI
print "using odbc...\n";
use DBI;
$dbName = "DBI:ODBC:DEMODATA";
$dbUserName = "";
$dbPassword = "";
print "connecting...\n";
$sql = "SELECT * FROM class";
$dbh = DBI->connect($dbName, $dbUserName, $dbPassword);
$dataObject = $dbh->prepare($sql);
$dataObject->execute();
while(@row=$dataObject->fetchrow_array)
{
print "$row[0]\t$row[1]\t$row[2]\n\n"
}