How do correctly create a uuid for a new database entry?

For php, the @sbecks solution works perfectly. I will only refine the link to a specific post, so as not to search. Here it is:

As for protection against a possible UUID repeat (I understand that the probability is extremely small, but there is an option to completely exclude such an event), I plan to solve this by using additional steps in the server action:

  1. UUID Generation will not be done while inserting a record, but before. The generation will be in a while loop, which will check whether the new uuid matches the existing ones in the database. If there is a match, the loop will repeat generation until a unique uuid is generated.
  2. at the stage of inserting a record, the value of the already generated and verified uuid from step 1 will simply be inserted into the field.

In this case, we will get 100% protection from possible UUID duplication.

1 Like