2
use DBI;
my $db_host = 'localhost';
my $db_user = 'postgres';
my $db_pass = '12345';
my $db_name = 'postgres';
my $db = "dbi:pg:dbname=${db_name};host=${db_host}";
$dbh = DBI->connect($db, $db_user, $db_pass,{ RaiseError => 1, AutoCommit => 0 }) || die "Error connecting to the database: $DBI::errstr\n";
my $query = "SELECT * FROM random_table";
$ref = $dbh->selectcol_arrayref($query);
print join("\n", @$ref);
當我執行此文件時。我收到一個錯誤。它說:如何使用perl連接到postgresql
DBD :: PG初始化失敗:通過包「DBD :: PG」
我是否需要安裝一些驅動程序連接到無法找到對象的方法「司機」數據庫..?
首先,您必須'使用strict'和'use warnings',並在使用它們時聲明'$ dbh'和'$ ref' – Borodin 2013-04-11 23:28:07