PDO connection with error check


Here is my DB connection:

try {
$pdo = new PDO('mysql:host=mysqlserver.no;mydbname=mydb', 'myusername',
$output = 'Database connection established.';
catch (PDOException $e) {
$output = 'Unable to connect to the database server: ' . $e->getMessage();

When it comes to error and connection check, or I start at the other end..:.
I know the error check works. I print both to screen. Checked it by entering both correct and incorrect passwords. So I'm sure it works, but does it only work on the user details, or will it work on other errors as well? For example, if there is no connection with the DB server, if it is on a separate server, for example?
read more about try ... catch block. It can catch each Exception/Throwable that was thrown in the try block. In that case if there is any reason why the connection is not established then a Exception should be thrown and catch.
I found out of it, but thanks anyway. Unfornatley it's so long ago so I cant remember what the solution was.