mysql compress 与 php gzcompress
2018-06-02 本文已影响0人
czxin
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" ) )