mysql compress 与 php gzcompress 的差异

mysql compress 编码后数据头部多出 4bit 原数据长度。
php 使用 gzuncompress 解码时需要去掉前 4bit 才能正常解码。
php 使用 gzcompress 编码时可以补上 4bit 原数据长度以兼容 mysql uncompress 方法

mysql 编码 -> php 解码

SELECT HEX( COMPRESS( "text" ) )
gzuncompress( substr( hex2bin( $date_hex ), 4 ) )

php 编码 -> mysql 解码
pack('i', strlen( $text ) ) . gzcompress( $text )
SELECT COMPRESS( UNHEX( "date_hex" ) )

你可能感兴趣的:(mysql compress 与 php gzcompress 的差异)