Are there PHP libraries to generate sequential GUIDs for usage in a MySQL database?
Asked
Active
Viewed 1,948 times
1
-
5Wouldn't MySQL's auto-increment capability suit your needs there? – Romain Dec 30 '09 at 11:08
-
2GUIDs aren't supposed to have a meaningful order - why do they need to be sequential? – Doug Dec 30 '09 at 11:20
-
4Sequential GUIDs may perform better when using as primary key. At least that's what I've heard (and I can imagine it's true). – openfrog Dec 30 '09 at 11:34
-
1@Romain Muller: Sure this is simpler, but there are some disadvantages to auto-increment keys, like cross-db merging, security (visitors or spambots iterate over your id's and get to every user, you may not want that), etc. – openfrog Dec 30 '09 at 11:35
-
why is that? Where have you read it (it, in fact, makes no sense at all)? – shylent Dec 30 '09 at 11:36
-
How is iterating over a Sequential ID more secure than iterating over sequential Ints? GUIDs are considered secure because they are non-predictable (if implemented correctly) – Michael Stum Dec 30 '09 at 11:47
-
@opencat; isn't it true that sequential GUID's are unique in the table itself, but not across the whole database (therefore, not being GUID but rather UID) and wouldn't merging still be a problem? A prefix to each ID would solve this. Also just using GUID's (without sequence) would. – Jake Dec 30 '09 at 14:08
-
No, depending on the algorithm (there isn't _the_ algorithm for seq.guids) they are guaranteed to be at least unique throughout the same machine. see http://en.wikipedia.org/wiki/Globally_Unique_Identifier#Sequential_Algorithms and http://msdn.microsoft.com/en-us/library/ms189786.aspx (and many more) There are also several "threads" on sequential guids here on SO, e.g. http://stackoverflow.com/questions/170346/what-are-the-performance-improvement-of-sequential-guid-over-standard-guid – VolkerK Dec 30 '09 at 14:58
-
There are several forms of GUIDs. In far past, most GUIDs were linked to a MAC address of a network card in the machine, plus a time signature, plus a time-change counter, plus a sequential component. These things together insured global uniqueness. After a while privacy concerns brought us the now-common "random" GUID which is VERY bad for key-splitting/index rebalancing. – IDisposable Dec 31 '09 at 06:01
-
@Doug GUID can be both random and sequential. They are supposed to be sequential if you intend to use them in a clustered index. See this [question](http://stackoverflow.com/questions/1757222/should-a-sequential-guid-primary-key-column-be-a-clustered-index) – Arialdo Martini Mar 08 '13 at 15:24
2 Answers
3
If you mean uuids based on a common prefix, such as MAC and time, have a look at uniqid. Here you can also find some code for RFC 4211 compliant UUIDS. If you want to be on the safe side, use this wrapper to libuuid: pecl uuid. Haven't tested it though, YMMV.

Alexander Torstling
- 18,552
- 7
- 62
- 74
1
I believe what is being asked for is, does MySQL have support for Sequential Id's the way that SQL Server does?
http://blogs.msdn.com/b/sqlserverfaq/archive/2010/05/27/guid-vs-int-debate.aspx
Now before everyone asks why use GUIDS, GUIDS will allow one to move/merge data between tables and databases.