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);
When I execute this file. I get an Error. It Says:
DBD::pg initialisation failed: Can't locate object method "driver" via package "DBD::pg"
Do I need to install some driver to connect to the database..?
It's dbi:Pg
, not dbi:pg
. Case matters.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.