Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 如果在perl中使用eval第一次数据库连接失败,如何连接第二个数据库_Mysql_Perl - Fatal编程技术网

Mysql 如果在perl中使用eval第一次数据库连接失败,如何连接第二个数据库

Mysql 如果在perl中使用eval第一次数据库连接失败,如何连接第二个数据库,mysql,perl,Mysql,Perl,我希望使用perl连接到数据库,但如果我的数据库连接失败,那么我希望使用eval函数连接到第二个数据库 my $dbh = eval { DBI->connect("DBI:mysql:host=$host1;database=$database", $user, $password, { 'RaiseError' => 1 }); }; if (!$dbh) { $dbh = DBI->connect("DBI:mysql:host=$ho

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

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 });
}