Cesar Cesar - 8 months ago 51
MySQL Question

How to make Symfony2 set the MySQL time_zone?

How can I set custom driver options in Symfony2?

In this case I want to run

SET time_zone = '-04:30'
in MySQL as part of the connection initialization.

Answer Source

Set in app/config/config.yml the following:

        driver:   %database_driver%
        host:     %database_host%
        port:     %database_port%
        dbname:   %database_name%
        user:     %database_user%
        password: %database_password%
        charset:  UTF8
        # Here we configure the custom driver options
        # In this case is PDO::MYSQL_ATTR_INIT_COMMAND
        # The constant can not be used in this context
        options: {1002: "SET time_zone = '-04:30'"}