Well...
function database_Test($host, $user, $password, $database)
{
$charset = 'utf8mb4';
$dsn = "mysql:host=$host;dbname=$database;charset=$charset";
$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
try {
$pdo = new PDO($dsn, $user, $password, $options);
return true;
} catch (\PDOException $e) {
return false;
}
}
What is the best way (practice) to test the MySQL connection on installation before continuing to write the configuration file?