unable to connect to multiple database using Dancer::Plugin::Database

雨燕双飞 提交于 2019-12-13 16:47:49

问题


I am using Dancer::Plugin::Database to connect with database from my dancer application. It works fine for single connection. When i tried for multiple connection i got error. How can i add multiple connection.

I added the following code in my config.yml file:

plugins:
        Database:
            connections:
                one:
                        driver: 'mysql'
                        database: 'employeedetails'
                        host: 'localhost'
                        port: 3306
                        username: 'remya'
                        password: 'remy@'
                        connection_check_threshold: 10
                        dbi_params:
                            RaiseError: 1
                            AutoCommit: 1
                        on_connect_do: ["SET NAMES 'utf8'", "SET CHARACTER SET 'utf8'" ]
                        log_queries: 1
                    two:
                        driver: 'mysql'
                        database: 'employeetree'
                        host: 'localhost'
                        port: 3306
                        username: 'remya'
                        password: 'remy@'
                        connection_check_threshold: 10
                        dbi_params:
                            RaiseError: 1
                            AutoCommit: 1
                        on_connect_do: ["SET NAMES 'utf8'", "SET CHARACTER SET 'utf8'" ]
                        log_queries: 1

Then i tried to connect with database using the following code :

my $dbh=database('one');
my $sth=$dbh->prepare("select * from table_name where id=?");
$sth->execute(1);

I got compilation error, "Unable to parse Configuration file"

Please suggest a solution.

Thanks in advance


回答1:


YAML requires consistent indentation for the keys of a hash. Remove four spaces from before "two:" and it should parse.

Update: I see there's been some editing of indentation; going back to the original question produces a parsing error in a different place and shows a mixture of tabs and spaces being used; try to consistently use only tabs or only spaces. You can test your file and find what line is producing the first error like so:

$ perl -we'use YAML::Syck; LoadFile "config.yml"'
Syck parser (line 19, column 16): syntax error at -e line 1, <> chunk 1.

Also make sure that your keys are all ending up in the right hash (the mixture of tabs and spaces seems to allow this coming out wrong but still parsing successfully) with:

perl -we'use YAML::Syck; use Data::Dumper; $Data::Dumper::Sortkeys=$Data::Dumper::Useqq=1; print Dumper LoadFile "config.yml"'


来源:https://stackoverflow.com/questions/13717588/unable-to-connect-to-multiple-database-using-dancerplugindatabase

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!