Codeigniter timezone mysql settings

后端 未结 5 971
花落未央
花落未央 2020-12-31 19:46

Just realised WHY my site is now showing all datetime variables as -1 hr... I\'m using Codeigniter for the first time! (Never had this problem before)

So, I have inc

5条回答
  •  臣服心动
    2020-12-31 20:02

    In config/autoload.php, set a model to load on each page load. then call $this->db->query("SET time_zone='+0:00'"); in that model constructor.

    config/autoload.php

    $autoload['model'] = array('default_model');// for ex, "say default_model"
    

    In application/models, create a new model file with name of "default_model.php" and add below code.

    application/models/default_model.php

    class Default_model extends CI_Model {
    
         function __construct()
         {
             // Call the Model constructor
             parent::__construct();
             $this->db->query("SET time_zone='+0:00'");
         }
     }
    

    On each page load, this constructor will be called and mysql timezone will be set to +0:00.

提交回复
热议问题