Since a while checking a connection to a database in a controller was working fine doing the following:
$em->getConnection()->connect();
$connected = $em->getConnection()->isConnected();
But I now have a deprecation:
php.INFO: User Deprecated: Public access to Connection::connect() is deprecated.
How should I test my database connection now ?
There is now a deprecation notice when connection is used outside the library:
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4966',
'Public access to Connection::connect() is deprecated.',
);
You need to use getNativeConnection()
instead (which is from the same Connection class)
$em->getNativeConnection()->isConnected();