Defeating weird “No database selected [Native Error: MySQL server has gone away]” error when moving code into a partial in Symfony

So you’re working in an older version of Symfony (or maybe even a newer one..), trying to refactor some common code into a partial. Maybe something simple like this from within a global partial?:

include_partial('status');

And suddenly connections to the database start falling down with errors along the lines of:

SQLException: No database selected [Native Error: MySQL server has gone away]

In reality this is a problem with Symfony’s error reporting from within global partials. Do you actually mean?:

include_partial('global/status');

Remember that even if you’re in a global partial, Symfony doesn’t really know that’s where you are.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.