PHP/MySQL: Storing and retrieving UUIDS -


I am trying to add UUID in some tables, but I'm not sure what is the best way to store / It will be recovered I think it is more efficient to use BINARY (16) instead of VARCHAR (36). After doing some research, I also came to know that you can convert UIIID string with binary:

  UNHEX (REULA (UUID), '-', ''))  

Forgive my ignorance, but is there an easy way to do it with PHP and then for readability, when it is needed, it is turned back into string?

In addition, would it be too much if I used it as a primary key instead of Auto_Increase, is it the difference?

Edit:

found a part of the answer:

  $ bin = pack "H *", str_replace ('-', '' , $ Guid));  

How do you open it?

OK - it's best to try to answer my own question With which I can come:

Pack:

  $ binary = pack ("h *", str_replace ('-', '', $ string));  

unpack

  $ string = unpack ("h *", $ binary); $ String = preg_replace ("/ ([0- 9A-F] {8}) ([0- 9A-F] {4}) ([0- 9AF] {4}) ([0- 9 A-F] {4}) ([0- 9A-F] {12}) / "," $ 1- $ 2- $ 3- $ 4- $ 5 ", $ string);  

Is there a problem in which anyone can see?


Comments