【问题标题】:How do i connect second database if my first database connection faild using eval in perl [closed]如果我的第一个数据库连接在 perl 中使用 eval 失败,我如何连接第二个数据库 [关闭]
【发布时间】:2016-06-22 06:18:26
【问题描述】:

我想使用 perl 连接到数据库,但是如果我的数据库连接失败,那么我想使用 eval 函数连接到我的第二个数据库。

【问题讨论】:

    标签: mysql perl


    【解决方案1】:
    my $dbh = eval { 
        DBI->connect("DBI:mysql:host=$host1;database=$database", 
            $user, $password, { 'RaiseError' => 1 });
    };
    if (!$dbh) {
        $dbh = DBI->connect("DBI:mysql:host=$host2;database=$database", 
            $user, $password, { 'RaiseError' => 1 });
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-24
      • 1970-01-01
      • 2018-09-07
      • 1970-01-01
      • 2021-12-27
      • 1970-01-01
      相关资源
      最近更新 更多