PHP/MySQL: Storing and retrieving UUIDS
Posted
by Greg
on Stack Overflow
See other posts from Stack Overflow
or by Greg
Published on 2010-05-15T05:31:27Z
Indexed on
2010/05/15
5:44 UTC
Read the original article
Hit count: 238
I'm trying to add UUIDs to a couple of tables, but I'm not sure what the best way to store/retrieve these would be. I understand it's far more efficient to use BINARY(16) instead of VARCHAR(36). After doing a bit of research, I also found that you can convert a UUID string to binary with:
UNHEX(REPLACE(UUID(),'-',''))
Pardon my ignorance, but is there an easy way to this with PHP and then turn it back to a string, when needed, for readability?
Also, would it make much difference if I used this as a primary key instead of auto_increment?
EDIT:
Found part of the answer:
$bin = pack("h*", str_replace('-', '', $guid));
How would you unpack it?
© Stack Overflow or respective owner