2017-02-24 155 views
1

鉴于这种简单的表:PostgreSQL的:插入带有默认时间戳的SQL语句 - dbeaver与PHP

create table comments (
    id numeric not null, 
    comment text, 
    created timestamp not null default now() 
); 

使用dbeaver直接从我的电脑数据库,并执行该语句

insert into comments (id, comment) 
select 1111, 'test'; 

的“创建“新记录的字段是:2017-02-24 16:17:21 这就是我的正确时间(CET)。

当我从一个php脚本(在连接到db的基于linux的web服务器上运行)运行完全相同的语句时,结果为2017-02-24 15:17:21。 Linux服务器时间没问题(即CET)。

我错过了什么?

+0

在您的PHP ini文件中,检查选定的时区。编辑:其实不太清楚为什么这会很重要 – Andy

+0

听起来就像你失踪了大约一小时 – pteronewone

+0

@pteronewone这是一个很好的:) –

回答

0

按答案为this link,你的表定义更改为

create table comments (
    id numeric not null, 
    comment text, 
    created timestamp not null default (now() at time zone ('CET')) 
); 

将使用所需的时区使用当前日期时间。