0

I am developing an online admission system with PHP and MYSQL database in which i will issue a unique form number to every applicants. Please keep in mind that the following format I will follow for the number e.g. 2016-00001 means year-00001. So for the first number I will insert the value in the database then after that the form numbers will be issued. According to my thinking following steps will be followed:

  1. Read form number from the form number table.
  2. increment the form number in the form number column.
  3. update the form number in the form number table.

Now I am thinking that what will happen if concurrent processes are occurred to the table, means many user access the table and read the value and update it at a same time than All of them will be assigned same form number. What steps should I follow to don't cause this problem.

Bilal Saqib
  • 87
  • 1
  • 1
  • 10
  • @drew this is a new question it is different from the other question The first form number will be in my own format that I will insert it to the table at first time. – Bilal Saqib Sep 27 '16 at 05:52
  • Check out an [Intention Lock](http://stackoverflow.com/a/38079598) answer of mine. That will give you a number safe from your peers via InnoDB row-level locking. Safe. Now you have a number. Right pad it if desired and add your prefix string in front. There is your string. Now do your insert. Safe as anything – Drew Sep 27 '16 at 05:56
  • So those are your two best bets for safety with concurrency. Allows you to not worry. `AUTO_INCREMENT` or Intention Lock – Drew Sep 27 '16 at 05:57
  • Also note that you changed the question after it was closed. Great for misspellings maybe. But your change pretty much changed the original question. That means ask a new question generally. That said, my Intention Lock link above should take care of you. – Drew Sep 27 '16 at 06:26

0 Answers0