J V J V - 4 months ago 26
PHP Question

DBAL connect immediately

In PDO (And likewise DBAL) if there's a problem authenticating with the server it will throw an exception containing a trace including the database username and password.

Needless to say, this is a problem, and in PDO I would wrap it in a try block and re-throw the error without the stack trace. Problem solved.

However, DBAL doesn't actually initiate the connection until the first query is called, so it misses the try block completely and spews my database credentials the first chance it gets!

How can I force DBAL to connect immediately so I can catch any authentication errors?

J V J V
Answer

\Doctrine\DBAL\Connection::connect()

Obvious in retrospect.