PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, ]); } catch (PDOException $e) { // If connection fails and we are not already on the install page, redirect to install.php if (basename($_SERVER['PHP_SELF']) !== 'install.php' && !headers_sent()) { header('Location: install.php'); exit; } throw $e; } } return $pdo; }