Setting default-time-zone on MySql Server via PhPMyAdmin

后端 未结 3 1727
粉色の甜心
粉色の甜心 2020-12-10 13:11

I have a shared hosting mySql instance which has it\'s system_time_zone set to Pacific Standard Time and it\'s time_zone variable set to System, hence effectively it\'s runn

相关标签:
3条回答
  • 2020-12-10 13:53
    <?php
    date_default_timezone_set('UTC'); //define local time
    
    $date=date('l jS \of F Y h:i:s A'); //type of time shown
    
    $conn=mysql_connect("localhost","root","") or die('Could not connect!'); //your database connection here
    
    $db_selected = mysql_select_db('databasename', $conn); //select db
    
    $result=mysql_query("INSERT INTO table (date) VALUES ('$date')", $conn); 
    ?>
    

    Simply sent the time as VARCHAR into db hope it helps and sorry for syntax errors (if there are any).

    0 讨论(0)
  • 2020-12-10 14:06

    For shared hosting, you have to ask support-guys to help you and change default time zone for you? I had similar problem with Arcor hosting-provider, called them and they fixed it. Before that, I found temporary solution in date_default_timezone_set() from PHP code. Probably the best solution is to ask someone who has privilege to change that parameter.

    0 讨论(0)
  • 2020-12-10 14:09

    In short, MySQL actually stores 'datetime' data type fields internally as UTC.

    However, PhpMyAdmin shows you the dates using the server default time, hence your confusion.

    For example, try adding this line before your SQL statement in PhpMyAdmin:

    SET @@session.time_zone='+00:00';
    SELECT * FROM MY_TABLE
    

    See the MySQL documentation for further details, or the answer in this post: How to correctly set mysql timezone

    Cheers Matt

    0 讨论(0)
提交回复
热议问题