mysqlにバイナリ16としてguid(実際にはファイル名を指す)を保存しています。この関数を使用してguidを生成しています
private function guid(){
if (function_exists('com_create_guid') === true) {
return trim(com_create_guid(), '{}');
}
return sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535),
mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535),
mt_rand(0, 65535), mt_rand(0, 65535));
}
関数を使用してGUIDをバイナリとして保存しています
$binary = pack("h*", str_replace('-', '', $guid ));
問題は、バイナリ フィールドをデータベースから guid に変換してファイルをリンクするときです。上記の guid 関数によって生成された元の guid を取得できません。この mysql ステートメントを使用して、バイナリ 16 を guid に変換します。
CONCAT(
HEX(SUBSTRING(hash,4,1)), HEX(SUBSTRING(hash,3,1)),
HEX(SUBSTRING(hash,2,1)), HEX(SUBSTRING(hash,1,1)) , '-',
HEX(SUBSTRING(hash,6,1)),HEX(SUBSTRING(hash,5,1)),'-',
HEX(SUBSTRING(hash,8,1)) , HEX(SUBSTRING(hash,7,1)),'-',
HEX(SUBSTRING(hash,9,2)),'-',HEX(SUBSTRING(hash,11,6))
)
ここで、hash はバイナリ 16 フィールドです。どんな手掛かり?
ありがとう。