I just learned that PDO and mysqli both do NOT throw exceptions by default. I learned that to make mysqli throw exceptions, one has to have this line of code:
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
and in PDO, one has to have this line of code:
There is one very significant difference between the two. In mysqli, that line of code is done BEFORE
obtaining a database connection. In PDO, that line of code is done AFTER
obtaining a database connection. In fact, PDO requires an already successful database connection before one can even tell it to throw exceptions.
So here is my question. In PDO, how can I use the try/catch block
to catch an incorrect user/password combination or incorrect database name while connecting to the database, an error condition that happens BEFORE having obtained a database connection?