I have a C# .NET 3.5 application using the ADO.NET Driver for MySQL (Connector/NET). It stores a Guid.NewGuid() in the MySQL database as a BINARY(16).
I have another application using PHP 5.3.4 that needs to be able to read that binary value as a GUID string and encode a GUID string in the same 16-byte binary value.
As an example I want to be able to convert between these two things:
GUID string: E241346C-504F-4BE5-BDF3-1B8274815597
BINARY(16): 65 32 34 31 33 34 36 63 2d 35 30 34 66 2d 34 62
How can I do this in PHP?
The problem was that the field was BINARY(16), but the My SQL connector was trying to store a CHAR(36) in there. (They changed the way GUIDs were formatted in v6.1.1)
So, the last 20 bytes of my GUID were being silently truncated. (I do not know why the connector didn’t throw an exception.)
Once I changed the database to store GUIDs as a CHAR(36), it worked fine. Alternatively, I could have use the
oldguids=trueelement in my connection string.