Re: safe way to retrieve the record i just inserted

From: Date: Sun, 24 Nov 2002 14:35:26 +0000
Subject: Re: safe way to retrieve the record i just inserted
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-23624@lists.php.net to get a copy of this message
Perhaps pg_last_oid() will help: http://www.php.net/manual/en/function.pg-last-oid.php --Dave Dave wrote:
Hi everyone, I am new to the forum. I am using PHP and PostgreSQL. After I insert into a table "Task" who's primary key is a serial type (auto sequence number) I would like to immediately retrieve that generated sequence number to use for subsequent inserts into another table "Points." So what is a correct and safe way to guarantee I can retrieve this record, without requiring another indexed (and unique) field? Example:
    //run in php, insert a new TASK
    INSERT INTO Task
        ("taskname", "taskstat")
    VALUES
        ("my new task", 0);
    //this part I need help with.
        //get the task_id of the new task from above
        $new_task_id = ????????;
    //run in php, insert a POINT, referencing the new TASK
    INSERT INTO Point
        ("task_id", "ptnotes")
    VALUES
        ($new_task_id, "this is a point with foreign key reference to the
new task");


« previous php.db (#23624) next »