We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 577
    • 132 Posts
    Is there a way to set the Timezone automatically at time of the xPDO connection. If not how could I go about getting it set.

    Using AWS RDS and you cannot set the default tz due to lack of SUPER user perms.
      "One of these days I will get around to my own website... Its only been about 12 years... maybe tomorrow smiley"
      • 34012
      • 88 Posts
      You can use pdo to set the timezone before query, kind of a nuisance to be honest but doable already googled how to create the offset (what you want I presume) http://www.sitepoint.com/synchronize-php-mysql-timezone-configuration/

      I could not find any possible way to do this on some certain constructor but you could use plugin (if using modx) to set timezone always on web init etc.

      Anyways, from the example instead of the $db (the connection object) you can set the time zone with
      $xpdo->exec("SET time_zone = '{$timezone}'"); //If not using MODX
      //OR
      $modx->exec("SET time_zone = '{$timezone}'");
      


      Obviously if you are using own xpdo application, you could override the xPDO __construct() on your own derivate class and set the timezone after connection.
        Almost retired from web-development industry but still randomly writing at Lazylegs.info and on schedule hopefully in near future to finish Oracle and PostgreSQL ports of MODX
        • 577
        • 132 Posts
        @lazylegs - Thanks for the info, yes I am using MODX and had hoped to be able to do this somehow on the constructor and not get a plugin involved.
          "One of these days I will get around to my own website... Its only been about 12 years... maybe tomorrow smiley"
          • 34012
          • 88 Posts
          Was just browsing system settings just for general interest and found next: Server Offset Time under core -> System and Server. Am not sure if it would help but guess that it might help. Also you can set php timezone from there. Am not sure if this will actually affect the MySQL environment at the background but could guess it compensates the time differences in php itself.

          Have not tried the setting so those who have experience could comment or just try it and see what happens wink
            Almost retired from web-development industry but still randomly writing at Lazylegs.info and on schedule hopefully in near future to finish Oracle and PostgreSQL ports of MODX
            • 577
            • 132 Posts
            Thank you for the added info. I am sure that is php only not myql. I have looked at the source connection xPDO classes and see nothing that is setting the TZ on connection or allowing for it.

            Your suggestion of a plugin may be my only option at this time.

            Thanks
            Adam
              "One of these days I will get around to my own website... Its only been about 12 years... maybe tomorrow smiley"
              • 22303 MODX Staff
              • 10,725 Posts
              Actually, the PDO MySQL driver provides a way to execute commands on connect and you can set this in your core/config/config.inc.php file:

              $config_options = array(
                  PDO::MYSQL_ATTR_INIT_COMMAND => "SET time_zone = '-6:00'",
              );


              Let me know if this works for you.
                • 577
                • 132 Posts
                @opengeek AWESOME !! Thank you

                For future knowledge I assume I can set as many commands as desired in the array and they will all iterate through.

                Also are all the config options documented anywhere or is it best to just refer the the code?
                  "One of these days I will get around to my own website... Its only been about 12 years... maybe tomorrow smiley"
                  • 22303 MODX Staff
                  • 10,725 Posts
                  Quote from: aesmith at Jul 25, 2012, 01:04 PM
                  For future knowledge I assume I can set as many commands as desired in the array and they will all iterate through.
                  I believe it only allows a single command, but I have not tested that.

                  Quote from: aesmith at Jul 25, 2012, 01:04 PM
                  Also are all the config options documented anywhere or is it best to just refer the the code?
                  You can see all the PDO MySQL-specific driver options at http://php.net/manual/en/ref.pdo-mysql.php in addition to the global ones at http://www.php.net/manual/en/pdo.constants.php (see those starting with PDO::ATTR_*).

                  xPDO (and thus modX) should accept any valid PDO driver options.