美文网首页
mysql compress 与 php gzcompress

mysql compress 与 php gzcompress

作者: czxin | 来源:发表于2018-06-02 17:20 被阅读0次

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

      本文链接:https://www.haomeiwen.com/subject/gavrsftx.html