Skip to content

Explain database session storage config in Flex #8420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
aik099 opened this issue Sep 23, 2017 · 3 comments
Closed

Explain database session storage config in Flex #8420

aik099 opened this issue Sep 23, 2017 · 3 comments

Comments

@aik099
Copy link

aik099 commented Sep 23, 2017

According to docs on https://symfony.com/doc/current/doctrine/pdo_session_storage.html page to avoid duplication the PdoSessionHandler needs to be configured like this:

services:
    # ...

    Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler:
        public:    false
        arguments:
            - 'mysql:host=%database_host%;port=%database_port%;dbname=%database_name%'
            - { db_username: '%database_user%', db_password: '%database_password%' }

Unfortunately when Symfony project is created using Flex there are no such container parameters anymore.

I've tried doing:

services:
    Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler:
        arguments: ['%env(DATABASE_URL)%']

but with DATABASE_URL defined in /.env as mysql://user:pass@127.0.0.1:3306/symfony?charset=utf8&serverVersion=5.5 it doesn't work and on attempt to save something to session I'm getting this error:

SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected
@sadikoff
Copy link
Contributor

sadikoff commented Sep 24, 2017

PdoSessionHandler uses default PDO and that's why default connection string doesn't works. The only way now is to write your own custom session handler to use connection string. You can extend bundled handler and rewrite constructor to parse string and define all vars needed.

or easier you can write all your vars in services.yaml

@aik099
Copy link
Author

aik099 commented Sep 24, 2017

Either duplicate DB connection data in config OR write only session handler. Both doesn't sound as correct approach.

Hopefully this issue would be addressed with Symfony 4.0 release.

@javiereguiluz
Copy link
Member

@aik099 thanks for reporting this problem. I agree that it's unfortunate to support incompatible DSN syntaxes. I've opened symfony/symfony#25186 to ask the community to add support to Doctrine DSN in future Symfony versions. So I'm closing this issue until the other one is fixed. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants