Note that this approach has risks around race conditions. Anytime you have a construct for the id you run the risk of having it create duplicate ids. You will need to handle that.


Sent from my iPod

On Sep 10, 2009, at 6:49 PM, Ben Dunlap <> wrote:

I assume that I can get increment value/sequence from db (I used harcoded
increment value  in the code above (generate_id(1))),
but I don't know how I can get this incremental value from db.I use mysql

If you're thinking of retrieving the newest value of an AUTO_INCREMENT
column, immediately after inserting a row, there are different ways to
do this depending on how you're connecting to MySQL.

PDO, for example, has a method called lastInsertId():

And the mysql_* family of functions has mysql_insert_id(), etc.


PHP General Mailing List (
To unsubscribe, visit:

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to