With the knowledge that EVERY request for a page would run this check, I would look into the php function for db connections.
I remember in a Yii1.1 app I had to do some stuff between App instantiation and running. code looked something like this
// instantiate and configure the application
$myApp = (new yii\web\Application($config));
// ---do stuff---
There are some things that are available from the $myApp-> methods, not sure what. You could do your check if the db server/table is available, then possibly redirect to a "we are closed" route if not available. This would give you the ability easily have the page look like the rest of the site. Maybe change the layout for no NavBar.