If you want to insert rows from different applications, then creating a UID through the database is the safest method, since the implementation is centralized and, of course, will not change between applications.
Suppose you decide to create an API in another language. Then you need to implement the same generator in this language. There may be differences in how this other language implements the functions you rely on to generate key data that leads to duplicate keys.
If you're just about to embed lines from PHP on your own server, it doesn't matter if you generate UIDs in the application or in the database.
The safe is not always right. Or practical. Weigh the pros and cons of your intended use cases from there.
David KJ
source share