Cesar Cesar - 15 days ago 6
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

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

doctrine:
    dbal:
        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'"}