Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP read binary UID value from MS sql as Hex
    text
    copied!<p>I have a code that generates UID:</p> <pre><code> $time_low = str_pad(dechex(mt_rand(0, 65535)), 4, '0', STR_PAD_LEFT) . str_pad(dechex(mt_rand(0, 65535)), 4, '0', STR_PAD_LEFT); $time_mid = str_pad(dechex(mt_rand(0, 65535)), 4, '0', STR_PAD_LEFT); $time_high_and_version = mt_rand(0, 255); $time_high_and_version = $time_high_and_version &amp; hexdec('0f'); $time_high_and_version = $time_high_and_version ^ hexdec('40'); // Sets the version number to 4 in the high byte $time_high_and_version = str_pad(dechex($time_high_and_version), 2, '0', STR_PAD_LEFT); $clock_seq_hi_and_reserved = mt_rand(0, 255); $clock_seq_hi_and_reserved = $clock_seq_hi_and_reserved &amp; hexdec('3f'); $clock_seq_hi_and_reserved = $clock_seq_hi_and_reserved ^ hexdec('80'); // Sets the variant for this GUID type to '10x' $clock_seq_hi_and_reserved = str_pad(dechex($clock_seq_hi_and_reserved), 2, '0', STR_PAD_LEFT); $clock_seq_low = str_pad(dechex(mt_rand(0, 65535)), 4, '0', STR_PAD_LEFT); $node = str_pad(dechex(mt_rand(0, 65535)), 4, '0', STR_PAD_LEFT) . str_pad(dechex(mt_rand(0, 65535)), 4, '0', STR_PAD_LEFT) . str_pad(dechex(mt_rand(0, 65535)), 4, '0', STR_PAD_LEFT); $guid = $time_low . '-' . $time_mid . '-' . $time_high_and_version . $clock_seq_hi_and_reserved . '-' . $clock_seq_low . '-' . $node; </code></pre> <p>It generates a string like: <strong>011FFF33-CA4A-44E8-8CD5-7344D8E94344</strong>. When I read it from MS SQL 2008 database, I get binary string like: <strong>3ÿJÊèDŒÕsDØéCD</strong>. How can I read it as hex string instead of binary string? Thanks! </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload