Answer the question
In order to leave comments, you need to log in
How to perform such an operation in mysql?
Good afternoon! There is a yii and mysql order acceptance system, when an order is placed, a form is opened, it is filled out and saved in the database, everything is implemented in one action, the customer wants the number of the future order to be displayed when the form is opened, the simplest solution came to mind is to simply get the id and add to +1 to it and display it to the user, but if an order is entered in parallel, a collapse may occur in the user's head, how else can such an action be performed?
Answer the question
In order to leave comments, you need to log in
Register the order in the database earlier. Accordingly, with the status "not confirmed".
Actually @Melkij wrote everything correctly.
At the same time, the customer will have statistics in the database on how many people do not fill out this form :)
No way. The generation of entity IDs before they were created was abandoned even in the 1C platform.
You can return an error and a new serial number in case of a collision of numbers from the server. But this is bullshit, really. Because if the number is needed right away, then on the basis of this number they will do something, tell it to someone.
And if after saving it can become irrelevant - then what's the point?
Another hardcore option is to maintain a global counter on the server, which will increase even if the order is not saved. In this case, you will have holes in the numbering when the order was filled in and not saved. But it will solve your specific problem.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question