2014-10-28 65 views
2

我使用Perl和我能夠連接到使用 此代碼Perl的DBI連接工程,但不能與催化劑

#!/usr/bin/perl 
use DBI; 
use strict; 
my $dbh = DBI->connect("dbi:Pg:dbname=postgres;host=127.0.0.1;port=5432", "postgres", "postgres", { RaiseError => 1 }) or die $DBI::errstr; 
$dbh->disconnect(); 
print "Done\n"; 

現在本地的PostgreSQL 9.3服務器,繼Catalyst documentation about PostgreSQL我嘗試生成催化劑模型。

我用這個shell命令

script/myapp_create.pl model DB DBIC::Schema MyApp::Schema \ 
create=static components=TimeStamp,EncodedColumn \ 
'dbi:Pg:dbname=postgres,host=127.0.0.1,port=5432' 'postgres' 'postgres' '{ AutoCommit => 1 }' 

,但我得到了以下錯誤:

DBIx::Class::Storage::DBI::catch {...}(): 
DBI Connection failed: 
DBI connect('dbname=postgres,host=127.0.0.1,port=5432','postgres',...) failed: 
FATAL: database "postgres,host=127.0.0.1,port=5432" does not exist at 
/usr/local/share/perl/5.18.2/DBIx/Class/Storage/DBI.pm line 1487. at 
/usr/local/share/perl/5.18.2/Catalyst/Helper/Model/DBIC/Schema.pm line 637 

回答

4

你的第一個DBI連接測試有使用分號正確配置的連接字符串「;」 - 你的第二個使用逗號',' - 這不是有效的屬性分隔符。

從;

'dbi:Pg:dbname=postgres,host=127.0.0.1,port=5432'... 

要;

'dbi:Pg:dbname=postgres;host=127.0.0.1;port=5432'... 
+3

哦,你說得對,糾正他們,命令的作品。這意味着,我必須更換眼鏡。在我這個年紀... – 2014-10-28 22:22:46