Skip to content
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

Symfony 2.3 RC1 and PdoSessionHandler #8095

Closed
t3chn0r opened this issue May 19, 2013 · 6 comments
Closed

Symfony 2.3 RC1 and PdoSessionHandler #8095

t3chn0r opened this issue May 19, 2013 · 6 comments

Comments

@t3chn0r
Copy link
Contributor

t3chn0r commented May 19, 2013

I just upgraded my project to 2.3.RC1 and now I'm getting this error, not sure if there's something new that I need to do now on my side or if there's something missing with the implementation of PdoSessionHandler:

_Fatal error: Uncaught exception 'InvalidArgumentException' with message '"Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler" requires PDO error mode attribute be set to throw Exceptions (i.e. $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION))' in /var/www/symfony23/vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php:52 Stack trace: #0 /var/www/symfony23/app/cache/dev/appDevDebugProjectContainer.php(2545): Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler->_construct(Object(PDO), Array) #1 /var/www/symfony23/app/bootstrap.php.cache(152): appDevDebugProjectContainer->getSession_Handler_PdoService() #2 /var/www/symfony23/app/cache/dev/appDevDebugProjectContainer.php(2571): Symfony\Component\DependencyInjection\Container->get('session.handler...') #3 /var/www/symfony23/app/bootstrap.php.cache(152): appDevDebugProjectContainer->getSession_Storage_NativeService() #4 /var/www/symfony23/app/cache/dev/ap in /var/www/symfony23/vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php on line 52

Regards

@jakzal
Copy link
Contributor

jakzal commented May 19, 2013

re #7634

@stof
Copy link
Member

stof commented May 20, 2013

@t3chn0r The fix is easy: configure your PDO instance to use exceptions, as described in the error message

@t3chn0r
Copy link
Contributor Author

t3chn0r commented May 20, 2013

@stof, but where exactly do I configure PDO? Right now the only code I have in my project related to PDO is the following lines in config.yml:

services:
    pdo:
        class: PDO
        arguments:
            - "mysql:host=%database_host%;port=%database_port%;dbname=%database_name%"
            - %database_user%
            - %database_password%

    session.handler.pdo:
        class: Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler
        arguments: [@pdo, %pdo.db_options%]

So, do I need to modify this component directly under the vendor directory?

@stof
Copy link
Member

stof commented May 20, 2013

you are doing it in your service definition:

services:
    pdo:
        class: PDO
        arguments:
            - "mysql:host=%database_host%;port=%database_port%;dbname=%database_name%"
            - '%database_user%'
            - '%database_password%'
        calls:
            - [setAttribute, [3, 2]] # \PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION

@t3chn0r
Copy link
Contributor Author

t3chn0r commented May 20, 2013

Perfect! 👍

Thanks a lot! I think the documentation in "The Book" should definitely add that for 2.3... ;)

@stof
Copy link
Member

stof commented May 20, 2013

Please open an issue on the symfony-docs repo (or even better a PR). And it is also true for older version btw (except it was not checking if you were messing its error handling or no).

I'm closing this ticket as there is no issue in the code

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

No branches or pull requests

3 participants