Generating an invoice number

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Generating an invoice number

Post by Luke »

I am creating a database, and to get an invoice number, I insert a blank row, use mysql_insert_id() to get the id number, and then update that row after getting all the information i need. Is there any danger of two people ordering off the site at once and mysql_insert_id selecting the wrong id?
User avatar
Nathaniel
Forum Contributor
Posts: 396
Joined: Wed Aug 31, 2005 5:58 pm
Location: Arkansas, USA

Post by Nathaniel »

I don't know that I would worry about that myself, but if you are, this guy has an interesting workaround.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

I've never run into any issues with mysql_insert_id() not providing me with the latest id.

If you're worried about it though, you could always create another field for the IP address or the like and then select the max id off of the table that matches the same ip.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

So do guys do that how I do it?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

as I said I use mysql_insert_id() and have never had an issue. I've used the scenario I described above for mssql queries though and it worked flawlessly as well.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Post Reply