Created
April 24, 2015 20:23
-
-
Save mirekfranc/e064c13ce6effd7d4eea to your computer and use it in GitHub Desktop.
How to access postresql from within perl script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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