我需要检查postgres数据库是否可用。
如果数据库在线,我会得到时间戳。
如果数据库离线,我会得到一个laravel PDO异常
但每次我收到异常并且脚本执行停止时
try
{
$con = new PDO("pgsql:host=".$db->Host.";port=".$db->Port.";dbname=postgres", $db->Username, $db->Password, [PDO::ATTR_TIMEOUT => '5']);
$dt = new 'DateTime(null, new 'DateTimeZone('Europe/Berlin'));
return $dt->getTimestamp();
}
catch(Exception $e)
{
return false;
}
catch(PDOException $e)
{
return false;
}
尝试在异常之前预写'
:
try
{
$con = new PDO("pgsql:host=".$db->Host.";port=".$db->Port.";dbname=postgres", $db->Username, $db->Password, [PDO::ATTR_TIMEOUT => '5']);
$dt = new 'DateTime(null, new 'DateTimeZone('Europe/Berlin'));
return $dt->getTimestamp();
}
catch('Exception $e)
{
return false;
}