I generate UUID
using INSERT INTO tbl1 (key, val) VALUES (UUID(), :value)
directly on MySQL using PDO. I don't have any idea how to remove those - (dashes) on MySQL side, on PHP side I can simply remove it using str_replace()
.
UUID() function in MySQL This function in MySQL is used to return a Universal Unique Identifier (UUID) generated according to RFC 4122, “A Universally Unique Identifier (UUID) URN Namespace”. It is designed as a number that is universally unique.
The following are the advantages of using UUID for a primary key: UUID values in MySQL are unique across tables, databases, and servers. It allows us to merge rows from distributed/different databases across servers. UUID values do not provide information about our data, which means it is hard to guess.
MySQL does not yet support setting a column's default value using a function (at least not yet as of version 5.6) but you can use a trigger instead. This post shows how to set a column to a UUID/GUID by default in MySQL using a trigger.
REPLACE(UUID(),'-','')
You don't need the UNHEX, just simply replace the hyphens.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With