Mysql 如果在perl中使用eval第一次数据库连接失败,如何连接第二个数据库
我希望使用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
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 });
}