in reply to Getting ID of last row inserted into database
Also, your select of the MAX(id) is subject to a race condition - if another user does an insert between the time you insert and you fetch the id, you will get their ID (probably not what you want). The DBI functions should be associated with your statement handles, so you shouldn't have that problem.
Re^2: Getting ID of last row inserted into database
by Yendor (Pilgrim) on Jan 26, 2006 at 15:15 UTC
|
Right.
That's an understood part of the problem, and also why my "select" solution felt like such a hack. I did my best to mitigate it by adding the FirstName/LastName to the WHERE clause when selecting the ID I was looking for.
At that point, the only race condition problem would have been on someone inserting the same data multiple times during the (acknowledged) race condition period.
| [reply] |
|