Re: best technique to get the ID of the last inserted value

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



im not sure, but i think you still want to surround the insert and the db
specific call to get the
last insert id within a transaction.

-nathan

On 7/20/07, Uber Wannabe <nucleargeekdown@xxxxxxxxx> wrote:

However, wouldn't obtaining the id in that manner still possibly lead to
duplication?  The DB would take care of the locking on the inserts, but
the
inserts would be populated from a non-locking select, right?  Which means
that, with two similar transactions getting ready to occur, you could end
up
with two Inserts with the same id.

Just my thought... I'd stick with the DB's built-in functionality for
that.
As usual, all the information on that is freely available online.


-- N/A

-----Original Message-----
From: Brad Bonkoski [mailto:bbonkoski@xxxxxxxxxxxxxx]
Sent: Friday, July 20, 2007 1:50 PM
To: Marcelo Wolfgang
Cc: php-general@xxxxxxxxxxxxx
Subject: Re:  best technique to get the ID of the last inserted value

One easy solution would be to get the ID before you do the insert....
i.e. in Oracle you would run the query:
select some_id_generating_seq.nextval from dual

and then you would use that id to insert and you would know the id after
that...and the DB would take care of locking and such.
So, check the help pages for your DB of choice to see what support they
have for something like that.

-B

Marcelo Wolfgang wrote:
> Hi all,
>
> I'm a newbie in PHP, and I want to know what's the best technique you
> guys use when you need to get the id of the last inserted value in the
> database.
>
> My first thought is to do a SELECT on the db and get the last id, but
> I know that if I have two almost simultaneous connections I may get
> the wrong one, so that's the why of my question.
>
> TIA
> Marcelo Wolfgang
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux