Hi!
I created a booking registration form the users fills up. Each information entered must be inserted in the database with a unique id. I formulated an id like BK00001-07.
WHERE:
BK is the prefix
00001 is a series that is stored in the database
07 is the current year
Before inserting the record, I get the next counter in the table named ba_booknoprefix. But since the script is for multiple users,I believe duplicate ids are possible to generate. How can I avoid this scenario? Can I use database transactions? Please give me example scripts.
Thank you!
Performing database transaction
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
- jlising
- Forum Commoner
- Posts: 33
- Joined: Mon Mar 19, 2007 1:48 am
- Location: Pampanga, Philippines
- Contact:
Thank you arborint!
Yes I am using MySQL. As my client required, I am not allowed to use auto increment instead, use the format with BK prefix, series and 2 digit current year. As now, I have a separate table for the counter which I update every record is inserted. Is there another efficient way to solve this?
Thanks again!
Yes I am using MySQL. As my client required, I am not allowed to use auto increment instead, use the format with BK prefix, series and 2 digit current year. As now, I have a separate table for the counter which I update every record is inserted. Is there another efficient way to solve this?
Thanks again!
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US