NYCPHP Meetup

NYPHP.org

[nycphp-talk] PEAR::DB insertID???

Adam Maccabee Trachtenberg adam at trachtenberg.com
Tue Mar 30 10:57:03 EST 2004


> I'm not using PEAR::DB (yet), but what I do with MySQL when I need to
> find this out is:
>
> 1) Lock the table
> 2) Insert what needs to get inserted
> 3) Query the ID out of the table order by id desc limit 1
> 4) Unlock the table

Bleach. :) Use mysql_insert_id() instead and you can skip the table locking.

http://us4.php.net/manual/en/function.mysql-insert-id.php

Yes, it's smart enough to return your insert id even if a different
process inserts another row into the table in between your insert and
the call to mysql_insert_id().

-adam

-- 
adam at trachtenberg.com
author of o'reilly's php cookbook
avoid the holiday rush, buy your copy today!



More information about the talk mailing list