In my webapp, I am going to accept all the database connection parameters (such as username, server, database etc.) as input from the users and before saving those information, I want to quickly test if a connection can be obtained successfully based on those connection parameters.
Here is my code:
$config = new \Doctrine\DBAL\Configuration();
$url = "mysql://user:pass@server/instance"; // INFORMATION FROM USER
$connectionParams = array('url' => $url);
try {
$conn = \Doctrine\DBAL\DriverManager::getConnection ($connectionParams, $config);
if ($conn->connect()) { // GETTING ERROR HERE
echo "Connection Successful";
}
}
catch (Exception $e)
{
echo "Connection unsuccessful";
}
But I am getting HTTP 500 error at connect()
call. My question is, how can I test if connection paremeters are valid?