保存到联机数据库和Localhost数据库

I'm trying to make a script when the Online Database is not available or the internet connection is interrupted it will save in the localhost database. I'm using PDO

This is what I'm trying to do

try
{
DBOnline (Insert values)
DBLocalhost(insert values)
}
catch(I dunno what to put here)
{
DB Localhost (save all)
}

Thank you Sir Mam

Use this on declaring database connection

try {
    $dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
    echo 'Connection failed: ' . $e->getMessage();
}

?> 

Try this:

try {
    $dbh = new PDO($online_host, $user, $password);
} catch (PDOException $e) {
    try {
        $dbh = new PDO($localhost, $user, $password);
    } catch (PDOException $ee) {
        echo 'Connection failed: ' . $ee->getMessage();
    }
}