In all these considerations, I assume that the reason for checking max id is to know which identifier should be next .. (if my maximum id is 5, then the next will be 5 + 1 = 6).
โ If this is not the reason, my best apologies
The case if the information of another INSERT user between your CHECK and INSERT will give an invalid identifier.
So, this can be resolved if you create a hash that may include a timestamp or other unique value.
Then in the same function you can insert your information with empty values โโand your hash. This would create an identifier if you selected AUTO_INCRECEMENT.
Then in the same function you will still have your hash, and you can search for id with the same hash. And then you can fill in the empty values โโwith mysql UPDATE.
This includes a bit more connections, but it is still a way to do this ...
Good luck with that.
Aurimas May 08 '13 at 22:30 2013-05-08 22:30
source share