title: How to connect to postgresql using perl
body: <pre><code>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-&gt;connect($db, $db_user, $db_pass,{ RaiseError =&gt; 1, AutoCommit =&gt; 0 }) || die "Error connecting to the database: $DBI::errstr\n";
  my $query = "SELECT * FROM random_table";
  $ref = $dbh-&gt;selectcol_arrayref($query);
  print join("\n", @$ref);
  </code></pre>
  
  <p>When I execute this file. I get an Error. It Says:</p>
  
  <blockquote>
    <p>DBD::pg initialisation failed: Can't locate object method "driver" via package "DBD::pg"</p>
  </blockquote>
  
  <p>Do I need to install some driver to connect to the database..?</p>