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