phpsqlframeworksmedoo

Medoo and Timezone


I use "Medoo" as a database framework.

My problem is I'm in Brazil, but my database (which is MySQL) is in Los Angeles, meaning the timezone is different.

I use the NOW() function of the database a lot and everything is like Los Angeles time.

Eventually this causes me issues.

With pure PHP, I usually resolve this as follows, however, with Medoo I do not know how to resolve:

mysql_query ('SET time_zone = "America / Sao_Paulo"');
mysql_connect ("host", "user", "password") or
    die ("Could not connect:". mysql_error ());
mysql_select_db ("database");
$ result = mysql_query ("myquery");

Did you realize that before the query, I made a SET in time_zone ? I do not know how to do this in Medoo or even leave it at the definitive setting.

Anyone have ideas on how to solve this?


Solution

  • Check out the documentation about initialization. There is a command option that will be executed after database connected. You can set the timezone there.

    $database = new Medoo([
        ...
    
        // [optional] Medoo will execute those commands after connected to the database for initialization
        'command' => [
            'SET SQL_MODE=ANSI_QUOTES'
        ]
    ]);