We help IT Professionals succeed at work.

Convert MySQL Binary field to HEX Value

craig-mcm
craig-mcm used Ask the Experts™
on
Hi,

I am currently amending an existing website which stores a Binary Value for Visitor ID.

When using myPhpAdmin the field is Defined as

idVisitor Binary(8)

And when i browse the data using phpMyAdmin i get the proper GUID returned in the cookie for visitor ID

idvisitor
74ab17c4eb1c0b72
a99881f08c8c6b58
1d10827a46a8b02d


When looking at the SQL export however it's outputing in binary:

idvisitor
't«Äë r' etc

How do i cast or convert the data in this column so that it displays the exact same GUID as phpMyAdmin produces.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Try the built-in PHP function bin2hex().

Author

Commented:
Is there no way this can be done at database level as opposed to in PHP code to produce the same ID?
Commented:
Ah, well closer to that request is to use the MySQL functions HEX() when reading and UNHEX() when storing.