1

UIDを生成するコードがあります:

        $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 & 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 & 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;

011FFF33-CA4A-44E8-8CD5-7344D8E94344のような文字列を生成します。MS SQL 2008データベースから読み取ると、 3ÿJÊèDŒÕsDØéCDのようなバイナリ文字列が表示されます。バイナリ文字列ではなく16進文字列として読み取るにはどうすればよいですか?ありがとう!

4

1 に答える 1

0

select呼び出しで文字列にキャストします-uidは、表示されている適切な16進文字列ではなく、生のビットに格納されます。mssqlドライバーは、おそらくこれらの生のビットを返し、読み取り可能な16進文字列自体に変換しないため、クエリで実行します。

于 2012-08-13T12:35:39.463 に答える