I'm using Phalcon PHP 3.0.4 and I'm not sure how to achieve this.
Given this MySQL MariaDB table schema:
CREATE TABLE `players` ( `Id` BINARY(16) NOT NULL, `Email` VARCHAR(255) NOT NULL, PRIMARY KEY (`Id`), INDEX `Email` (`Email`) ) COLLATE='utf8_general_ci' ENGINE=InnoDB ;
How would I achieve the following (using a Phalcon PHP preferred approach):
Take a regular HEX string either with or without dashes (example '15E077BCFD8511E683A600FF8A8C8699') in PHP and convert it to Binary(16) just before Phalcon saves the 'Id' property to the 'Id' column?
- Take the value of the 'Id' column and convert it back to a HEX string from Binary(16) so the result would be a Hex string either with or without dashes?
I followed this article for storing GUIDs as Primary keys in MariaDB and then I realized that the Hex/Binary conversion really needs to happen in PHP so Phalcon won't store binary data in it's model objects in memory.
At the end of the day this 'Id' column value is passed around in the HTTP request and responses to be used in other systems. Therefore passing around binary GUIDs is not going to work for me, hence why I need to convert it between strings and binary just before it enters and leaves the DB.