无法连接到Postgres

时间:2015-09-14 13:59:22

标签: database perl postgresql cpan

我试图连接到postgres db。无论如何我做错了,因为我收到了这个错误:

invalid connection option "DBI:Pg:dbname"

这里是代码段:

  my $dbinstance = "DBI:Pg:dbname=DB_NAME;host=111.222.111.2;port=1234";
  my $dbdriver = DBI->install_driver('Pg');
  if ( !$dbdriver ) {
      $dberror = "Load driver: " . $dbdriver->errstr;
  }

  $database = $dbdriver->connect(
        $dbinstance,
        $dbuser,
        $dbpassword,
        {
            RaiseError => 1,
            AutoCommit => 0
        }
    ) or die($dbdriver->errstr);

有任何线索吗?

提前致谢!

问候。

1 个答案:

答案 0 :(得分:3)

更改以下行:

$database = $dbdriver->connect(...)

用这个:

$database = DBI->connect(...)