I am building a project with installation (suck as WordPress) and the user provides database information (server, username, password and database). Now, I have to check if it can connect to the provided database. I tried this code, but it seems that it does not work (I am using Mysqli btw):
public function checkDataBaseConnection($server, $user, $pass, $db)
{
$conn = @mysqli_connect($server, $user, $pass, $db);
if(mysqli_connect_error())
{
return FALSE;
}
else
{
mysqli_close($conn);
return TRUE;
}
}
What other way can I use to check if the server can connect to the database?