如何将日期值插入到PostgreSQL表中?

3
如何在PostgreSQL中插入日期?以下方法是错误的:
public function insert( $name, $author ) {
    $this->query = "INSERT INTO people ( name, author, date )
    VALUES ( '$name', '$author', to_timestamp('2/3/2016 12:05')";

    return $result = pg_query( $this->connection, $this->query );
}

$database->insert( 'someName', 'SomeAuthor' );

问题在于您没有使用参数来传递参数。而且您正在使用非标准的日期/时间格式。 - Gordon Linoff
1个回答

3

'2016-03-02 12:05:00'是一种表示时间的方式...

$this->query = "INSERT INTO people ( name, author, date )
    VALUES ( '$name', '$author', '2016-03-02 12:05:00')";

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接