无法使用Dancer :: Plugin :: Database连接到多个数据库 [英] unable to connect to multiple database using Dancer::Plugin::Database

查看:115
本文介绍了无法使用Dancer :: Plugin :: Database连接到多个数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Dancer :: Plugin :: Database从我的Dancer应用程序连接数据库。它适用于单连接。当我尝试多个连接时出现错误。我如何添加多个连接。



我在config.yml文件中添加了以下代码:

 插件:
数据库:
连接:
一个:
驱动程序:'mysql'
数据库:'employeedetails'
主机:'localhost'
端口:3306
用户名:'remya'
密码:'remy @'
connection_check_threshold:10
dbi_params:
RaiseError: 1
自动提交:1
on_connect_do:[ SET NAMES'utf8', SET CHARACTER SET'utf8']
log_queries:1
2:
驱动程序:'mysql'
数据库:'employeetree'
主机:'l ocalhost'
端口:3306
用户名:'remya'
密码:'remy @'
connection_check_threshold:10
dbi_params:
RaiseError:1
自动提交:1
on_connect_do:[ SET NAMES'utf8', SET CHARACTER SET'utf8']
log_queries:1

然后我尝试使用以下代码连接数据库:

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

编译错误,无法解析配置文件



请提出解决方案。



预先感谢

解决方案

YAML需要哈希键的一致缩进。



更新:我看到缩进有一些编辑;请注意,缩进应为空格。



回到原始问题会在另一个位置产生解析错误,并显示使用的制表符和空格的混合;尝试始终仅使用制表符或仅使用空格。您可以测试您的文件,然后找出是什么行产生了第一个错误,如下所示:

  $ perl-我们使用YAML ::塞克LoadFile config.yml’
Syck解析器(第19行,第16列):-e第1行的语法错误,<>块1.

还请确保您的键全部以正确的哈希结尾(制表符和空格似乎可以解决这个问题,但仍然可以成功解析):

  perl-我们使用YAML :: Syck ;使用Data :: Dumper; $ Data :: Dumper :: Sortkeys = $ Data :: Dumper :: Useqq = 1;打印Dumper LoadFile config.yml’


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

解决方案

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"'

这篇关于无法使用Dancer :: Plugin :: Database连接到多个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆