Skip to content

Instantly share code, notes, and snippets.

@mirekfranc
Created April 24, 2015 20:23
Show Gist options
  • Save mirekfranc/e064c13ce6effd7d4eea to your computer and use it in GitHub Desktop.
Save mirekfranc/e064c13ce6effd7d4eea to your computer and use it in GitHub Desktop.
How to access postresql from within perl script
#!/usr/bin/env perl
# yum -y install perl-DBD-Pg
use DBI;
use warnings;
$HOST = 'localhost';
$NAME = 'db';
@USER_RO = ('readonly', 'guest');
$db = DBI->connect ("DBI:Pg:dbname=$NAME;host=$HOST", $USER_RO[0], $USER_RO[1])
or die "unable to open database", DBI->errstr;
$query = $db->prepare ("SELECT * FROM get_testcases (?)");
$query->execute ('441147');
if ($query->rows)
{
while (@fields = $query->fetchrow_array)
{
print join (":", @fields), "\n";
}
}
$db->disconnect;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment