开发者

How to insert timestampz values in postgresql table using php

We have one 2 field in of type 'tim开发者_开发问答estampz' like createdon & updatedon

createdon field is inserted using 'Now()' function of postgresql.

and i need to insert updatedon field by using php. like i try to insert using 'date( 'Y-m-d H:i:s' , $timestamp );'.

When i try to get updated field is gives me wrong result.

I want to know i want to insert timestampz using php how i can to that.


The following article describes how to implement the timestamp behavior of MySql with Postgres:

  • http://www.depesz.com/index.php/2008/05/08/mysqls-timestamp-in-postgresql/

It works by creating a trigger:

CREATE OR REPLACE FUNCTION trg_handle_timestamp() RETURNS TRIGGER AS $BODY$
BEGIN
IF NEW.y = OLD.y THEN NEW.y := now(); END IF;
RETURN NEW;
END;
$BODY$ LANGUAGE 'plpgsql';
CREATE TRIGGER trg_handle_timestamp 
BEFORE UPDATE ON test FOR EACH ROW EXECUTE PROCEDURE trg_handle_timestamp();


Can't you do something like "UPDATE table SET ..., updatedon = NOW() WHERE ..."?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜