php - PostgreSQL:使用默认时间戳插入 sql 语句 - dbeaver 与 php

标签 php linux postgresql dbeaver sql-timestamp

给定这个简单的表格:

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

直接在我的电脑上的数据库上使用 dbeaver,并执行此语句

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

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

当我从 php 脚本(在连接到数据库的基于 linux 的网络服务器上运行)运行完全相同的语句时,结果是 2017-02-24 15:17:21。 linux服务器时间ok(即CET)。

我错过了什么?

最佳答案

根据 this link 的回答,将表定义更改为

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

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

关于php - PostgreSQL:使用默认时间戳插入 sql 语句 - dbeaver 与 php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42442539/

相关文章:

php - 数组搜索的问题

php - 在wordpress中上传图片时出现HTTP错误

javascript - 多次使用 MySQLi 查询结果数组

linux - 无法从 Linux EC2 实例到本地计算机的 SCP

python - 解释了正确的守护程序行为(来自PEP 3143)

linux - Node js + Nginx + 亚马逊 Linux + SSL

sql - 如何在 CREATE TABLE 查询中命名 NOT NULL 约束

sql - 如何在 postgresql 中更新表

php - 将 JSON 字典值存储到变量中

python - 如何使用python自动将基于CSV的表创建到postgres中